【发布时间】:2014-01-25 21:00:24
【问题描述】:
我的 python 应该使用五个参数执行 /home/file.sh,如下所示。但是,每次我执行我的 python 脚本时,它都会忽略参数,并且 shell 脚本使用默认值执行。我也尝试过将 shell 设置为 False,但没有成功。有任何想法吗 ?提前谢谢!
var1='-t'
var2='m'
var3='20130105'
var4='-f'
var5='test.txt'
process=subprocess.Popen(['/home/file.sh', str(var1), str(var2), str(var3), str(var4), str(var5)],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait()
lists=process.communicate()[0]
我尝试了以下方法,但它再次使用默认参数
process=subprocess.Popen(['/home/file.sh -t m 20140105 -f test.txt')],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
【问题讨论】:
-
另外,请注意您不必明确地
wait,因为communicate意味着等待进程退出。
标签: python shell subprocess sh