【发布时间】:2015-02-18 06:02:33
【问题描述】:
我想从我的 python 脚本中调用一个 shell 脚本。我需要将 3 个参数/参数传递给 shell 脚本。我可以调用 shell 脚本(与 python 脚本在同一目录中),但是参数传递存在一些问题
from subprocess import call
// other code here.
line = "Hello"
// Here is how I call the shell command
call (["./myscript.sh", "/usr/share/file1.txt", ""/usr/share/file2.txt", line], shell=True)
In my shell script I have this
#!/bin/sh
echo "Parameters are $1 $2 $3"
...
Unfortunately parameters are not getting passed correctly.
I get this message:
Parameters are
None of the parameter values are passed in the script
【问题讨论】:
-
与推荐使用的
shell=False配合得很好——为什么你认为你需要shell=True代替?! -
无论如何你都不想要
shell=True的列表参数。
标签: python shell subprocess