2

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
1
  • 1
    Use a list of args Commented Jun 29, 2016 at 23:11

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

4 Comments

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?
I believe so, it works if I just run python3 wig.py google.com
yup! The directory I run this script in has wig.py in the same folder
I believe it works if I do this: process = subprocess.call('python3 wig.py {}'.format(var), shell=True, stdout=subprocess.PIPE) print process.returncode

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.