0
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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
shubham
  • 125
  • 5

1 Answers1

3

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)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • i am still getting a traceback File "./parent.py", line 4, in 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 710, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory – shubham Aug 05 '15 at 13:56
  • @shubham: and what would that traceback be? – Martijn Pieters Aug 05 '15 at 13:57
  • @shubham: so you don't have an executable `inversion_remover.py` in the path. Try using the full path? Are you sure the script is executable? – Martijn Pieters Aug 05 '15 at 13:59
  • yup its present in that directory – shubham Aug 05 '15 at 14:03
  • how do I check whether a script is executble or not?? – shubham Aug 05 '15 at 14:22
  • @shubham: is this Windows or a POSIX-compatible OS (Linux, Mac), or something else? Your traceback suggests a POSIX system. Is the executable bit set? `chmod +x filename` will set it. Is there a `#!...` shebang line at the top? – Martijn Pieters Aug 05 '15 at 14:25
  • @shubham: see [What do I use on linux to make a python program executable](http://stackoverflow.com/q/304883) – Martijn Pieters Aug 05 '15 at 14:26
  • i made all the files executible .still getting the traceback – shubham Aug 05 '15 at 15:10
  • @shubham: what does `print os.getcwd()` tell you is your current working directory? – Martijn Pieters Aug 05 '15 at 16:22
  • So, when navigating to that folder, `./inversion_remover.py` works? Does using the *full path* (instead of `./`) work? – Martijn Pieters Aug 05 '15 at 18:10