[英]traceback while using subprocess.call
import sys
import subprocess
arg1= sys.argv[1]
subprocess.call("inversion_remover.py",arg1)
subprocess.call("test3.py")
subprocess.call("test4.py")
I am getting the following traceback 我得到以下回溯
Traceback (most recent call last):
File "parent.py", line 4, in <module>
subprocess.call("inversion_remover.py",arg1)
File "/usr/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 659, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
How do I solve the above traceback? 如何解决上述回溯?
You need to pass in the command as a list : 您需要将命令作为列表传递:
subprocess.call(["inversion_remover.py", arg1])
subprocess.call(["test3.py"])
subprocess.call(["test4.py"])
otherwise your arg1
value is passed on to the underlying Popen()
object as the bufsize
argument. 否则,您的arg1
值将作为bufsize
参数传递给基础Popen()
对象。
Note that the scripts must be found on the path . 请注意,必须在路径上找到脚本。 If you want to execute these files from the local directory either prefix the path with ./
, or extend the PATH
environment variable to include the current working directory: 如果要从本地目录执行这些文件,请在路径前添加./
,或扩展PATH
环境变量以包括当前工作目录:
subprocess.call(["./inversion_remover.py", arg1])
subprocess.call(["./test3.py"])
subprocess.call(["./test4.py"])
or 要么
import os
env = os.environ.copy()
env['PATH'] = os.pathsep.join(['.', env['PATH']])
subprocess.call(["inversion_remover.py", arg1], env=env)
subprocess.call(["test3.py"], env=env)
subprocess.call(["test4.py"], env=env)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.