I am working to automate the Wig tool in python, which will involve including a URL.
Currently I take in user input (a URL) but am having difficulty adding it to the end of the subprocess call.
import subprocess
var = raw_input("Enter a URL: ")
subprocess.call('python3 wig.py ', var)
I know this is probably a simple question, but any help would be appreciated!
asked Jun 29, 2016 at 23:07
arcade16
1,5454 gold badges25 silver badges46 bronze badges
-
1Use a list of argsPadraic Cunningham– Padraic Cunningham2016年06月29日 23:11:57 +00:00Commented Jun 29, 2016 at 23:11
1 Answer 1
Pass the arguments as a list as @PadraicCunningham suggests:
args = ['python3','wig.py']
args.append(var)
subprocess.call(args)
If your argument list becomes long and complicated you can bring in shlex:
import shlex
args = shlex.split('python3 wig.py {}'.format(var))
subprocess.call(args)
answered Jun 29, 2016 at 23:09
mechanical_meat
170k25 gold badges238 silver badges231 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
arcade16
I am getting an error: Traceback (most recent call last): File "automate_wig.py", line 5, in <module> subprocess.call('python3 wig.py {}'.format(var)) 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...Any ideas what could be causing it?
arcade16
I believe so, it works if I just run python3 wig.py google.com
arcade16
yup! The directory I run this script in has wig.py in the same folder
arcade16
I believe it works if I do this: process = subprocess.call('python3 wig.py {}'.format(var), shell=True, stdout=subprocess.PIPE) print process.returncode
lang-py