将 subprocess.Popen 与自定义参数一起使用时 Python 出错

Error in Python when using subprocess.Popen with custom arguments

我在 Python 中使用 subprocess.Popen 并带有以下参数(我正在使用 pickle):

p = subprocess.Popen(args, stdout=subprocess.PIPE)

其中 args 为:

['python', 'pyAppScript.py', 'C:\Users\Herve\AppData\Local\Temp\app.pkl', 2, 'event=True;-;event:bool', 'published=True;-;value:int']

app.pkl 之后的参数是我用来设置未编组实例的自定义参数。 我有以下堆栈跟踪:

  File "D:\Java\framework\code\framework\samples\python\sample8\pythonHttpUtils.py", line 448, in createSubProcess
  p = subprocess.Popen(args, stdout=subprocess.PIPE)
  File "C:\Users\Herve\anaconda3\lib\subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Herve\anaconda3\lib\subprocess.py", line 1251, in _execute_child
args = list2cmdline(args)
  File "C:\Users\Herve\anaconda3\lib\subprocess.py", line 553, in list2cmdline
for arg in map(os.fsdecode, seq):
  File "C:\Users\Herve\anaconda3\lib\os.py", line 818, in fsdecode
filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not int

如果我不使用我的自定义参数而只做:

p = subprocess.Popen(['python', 'pyAppScript.py', 'C:\Users\Herve\AppData\Local\Temp\app.pkl'], stdout=subprocess.PIPE)

它工作得很好。我做错了什么?

我的错误是 args 是:

['python', 'pyAppScript.py', 'C:\Users\Herve\AppData\Local\Temp\app.pkl', 2, 'event=True;-;event:bool', 'published=True;-;value:int']

本来应该是:

['python', 'pyAppScript.py', 'C:\Users\Herve\AppData\Local\Temp\app.pkl', '2', 'event=True;-;event:bool', 'published=True;-;value:int']