arcade16 arcade16 - 5 months ago 8
Python Question

User input in subprocess call?

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!

Answer

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)