如何从python代码调用shell脚本? [英] How to call a shell script from python code?
本文介绍了如何从python代码调用shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从python代码调用shell脚本?
解决方案
subprocess模块会帮助你.
明显微不足道的例子:
<预><代码>>>>导入子流程>>>subprocess.call(['sh', './test.sh']) # 感谢@Jim Dennis 提出 []0>>>其中 test.sh
是一个简单的 shell 脚本,0
是这次运行的返回值.
How to call a shell script from python code?
解决方案
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.
这篇关于如何从python代码调用shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文