shell command python code example
Example 1: python execute shell command and get output
import subprocess
process = subprocess.Popen(['echo', 'More output'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
stdout, stderr
Example 2: shell command python
import subprocess
subprocess.run(["ls", "-l"])
Example 3: python execute shell command
python3 yourcode.py
or
python yourcode.py