shubham
shubham

Reputation: 125

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?

Upvotes: 0

Views: 1117

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124170

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.

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:

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)

Upvotes: 3

Related Questions