How to call a shell script from python code?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- How to get the return code of a shell script in lu
- Evil ctypes hack in python
Use the subprocess module as mentioned above.
I use it like this:
Subprocess is good but some people may like scriptine better. Scriptine has more high-level set of methods like shell.call(args), path.rename(new_name) and path.move(src,dst). Scriptine is based on subprocess and others.
Two drawbacks of scriptine:
Assuming test.sh is the shell script that you would want to execute
The subprocess module will help you out.
Blatantly trivial example:
Where
test.sh
is a simple shell script and0
is its return value for this run.Please Try the following codes :
In case the script is having multiple arguments
Output will give the status code. If script runs successfully it will give 0 otherwise non-zero integer.
Below is the test.sh shell script.