Check for external commands in python

import shutil

if shutil.which('ls'):
	subprocess.call(["ls"])

shutil.which returns the path of the specified command if found, or None if not found.

Recommended Posts

Check for external commands in python
Check for memory leaks in Python
Run shell commands in python
Execute external command in python
Search for strings in Python
Techniques for sorting in Python
External command execution in Python
About "for _ in range ():" in python
Existence check of external command in Python (like `which`)
Execute external commands in python (both receiving/not receiving results)
8 Frequently Used Commands in Python Django
Check the operation of Python for .NET in each environment
Check and move directories in Python
Run unittests in Python (for beginners)
How to execute external shell scripts and commands in python
Create your own Linux commands in Python
Check the behavior of destructor in Python
Notes on nfc.ContactlessFrontend () for nfcpy in python
Inject is recommended for DDD in Python
Check and receive Serial port in Python (Port check)
Tips for dealing with binaries in Python
Summary of various for statements in Python
Type annotations for Python2 in stub files!
Check if the URL exists in Python
Template for writing batch scripts in python
How to check opencv version in python
Process multiple lists with for in Python
Store RSS data in Zabbix (external check)
MongoDB for the first time in Python
Find and check inverse matrix in Python
Get a token for conoha in python
Sample for handling eml files in Python
AtCoder cheat sheet in python (for myself)
I searched for prime numbers in python
Notes for using python (pydev) in eclipse
Tips for making small tools in python
Use pathlib in Maya (Python 2.7) for upcoming Python 3.7
SublimeText2 and SublimeLinter --Syntax check for Python3--
Quadtree in Python --2
Python in optimization
python [for myself]
CURL in python
Geocoding in python
SendKeys in Python
Python nan check
Meta-analysis in Python
python grammar check
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python