【问题标题】:Error in Python when using subprocess.Popen with custom arguments使用带有自定义参数的 subprocess.Popen 时 Python 出错
【发布时间】:2021-10-15 17:40:30
【问题描述】:

我在 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)

完美运行。我做错了什么?

【问题讨论】:

    标签: python pickle popen


    【解决方案1】:

    我的错误在于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']
    

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      相关资源
      最近更新 更多