How to call a shell script from python code?

How to call a shell script from python code?

Answer rating: 300

The subprocess module will help you out.

Blatantly trivial example:

>>> import subprocess
>>> subprocess.call(["sh", "./test.sh"]) # Thanks @Jim Dennis for suggesting the []
0 
>>> 

Where test.sh is a simple shell script and 0 is its return value for this run.





Get Solution for free from DataCamp guru