Search code examples
pythonpicklepopen

Error in Python when using subprocess.Popen with custom arguments


I'm using subprocess.Popen in Python with the following arguments (I'm using pickle):

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

with args being:

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

The arguments after the app.pkl are custom arguments which I use to setup my unmarshalled instance. I have the following stack trace:

  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

If I don't use my custom arguments and just do:

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

It works perfectly. What did I do wrong?


Solution

  • My mistake was with args being:

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

    while it should have been:

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