use*_*173 26 python bash arguments subprocess popen
如何使用子进程模块运行bash脚本,我必须给出几个参数?
这就是我目前使用的:
subprocess.Popen(['/my/file/path/programname.sh', 'arg1 arg2 %s' % arg3], \
shell = True)
Run Code Online (Sandbox Code Playgroud)
bash脚本似乎没有采用任何参数.任何见解都非常感谢!
jfs*_*jfs 39
将参数作为列表传递,请参阅文档中的第一个代码示例:
import subprocess
subprocess.check_call(['/my/file/path/programname.sh', 'arg1', 'arg2', arg3])
Run Code Online (Sandbox Code Playgroud)
如果arg3
不是字符串; 在传递给check_call()
:之前将其转换为字符串arg3 = str(arg3)
.
小智 6
subprocess.Popen(['/my/file/path/programname.sh arg1 arg2 %s' % arg3], shell = True).
Run Code Online (Sandbox Code Playgroud)
如果使用shell = True
脚本,则必须将其参数作为字符串传递。args
序列中的任何其他元素都将被视为shell的参数。
您可以在http://docs.python.org/2/library/subprocess.html#subprocess.Popen找到完整的文档。
归档时间: |
|
查看次数: |
61234 次 |
最近记录: |