How to call a shell script from python code?

unk1102 picture unk1102 · Sep 23, 2010 · Viewed 365.1k times · Source

How to call a shell script from python code?

Answer

Manoj Govindan picture Manoj Govindan · Sep 23, 2010

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.