我试图从蟒蛇执行shell脚本(而不是命令):的Python:执行shell脚本参数(变量),但参数不是shell脚本读取
main.py
-------
from subprocess import Popen
Process=Popen(['./childdir/execute.sh',str(var1),str(var2)],shell=True)
execute.sh
----------
echo $1 //does not print anything
echo $2 //does not print anything
VAR1和VAR2是一些字符串我用作shell脚本的输入。我是否错过了一些东西,或者有另一种方式去做?
简称:How to use subprocess popen Python
是的...这是有用的它解决了我的问题。 – creativeDrive
@ user2837135如果它解决了你的问题,你应该接受它(点击复选标记),也可以考虑upvoting。 – SethMMorton
在这种情况下''= True''不应该被使用,但是如果你使用它,那么你应该使用['shlex.quote()'](http://docs.python)来转义'var1','var2'。 org/3/library/shlex.html#shlex.quote):'output = check_output(“./ childdir/execute.sh”+“”.join(pipes.quote(str(v))for v in [var1, var2]),shell = True)' – jfs