I have a python program gold.py located at /home/laxmi/Desktop/gold/gold.py in ubuntu. I have a python program test.py as test.py
import subprocess
subprocess.Popen("python", "Desktop/gold/gold.py")
I want this program to call the gold.py program and display the result from gold.py
error
File "/usr/lib/python2.7/subprocess.py", line 660, in __init__
raise TypeError("bufsize must be an integer")
You're getting a TypeError
. Since you're not passing keyword arguments, the second parameter is taken to be the buffer size, which must be an integer.
Change:
subprocess.Popen("python", "Desktop/gold/gold.py")
To:
subprocess.Popen("python Desktop/gold/gold.py")
Here's the documentation for subprocess.Popen. The first parameter, the only required one is args
:
args should be a sequence of program arguments or else a single string. By default, the program to execute is the first item in args if args is a sequence. If args is a string, the interpretation is platform-dependent and described below. See the shell and executable arguments for additional differences from the default behavior. Unless otherwise stated, it is recommended to pass args as a sequence.
NB:
If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.
So, if this needs to be done, you would do:
subprocess.Popen("python Desktop/gold/gold.py", shell = True)
Please read about the security risks intrinsic to this in the link provided.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments