0
argument_list = ['name=Jon', 'id=100' ] output = subprocess.check_output( ['/usr/bin/python', 'test.py', argument_list ], stderr=subprocess.STDOUT) 

In simple terms, I am trying to invoke a script using subprocess called test.py; I want to pass arguments to test.py through a list. Importatnt - List can be of any size.

Things I tried ,

output = subprocess.check_output( ['/usr/bin/python', 'test.py', ", ".join(argument_list) ], stderr=subprocess.STDOUT) 

and

output = subprocess.check_output( ['/usr/bin/python', 'test.py', '%s' % argument_list ], stderr=subprocess.STDOUT) 

Neither works because in subprocess.checkoutput should be (' ', ' ' ,' ') etc....

Is there a better way to do this ?

1 Answer 1

3

You can make a new list by adding lists together:

output = subprocess.check_output(['/usr/bin/python', 'test.py'] + argument_list, stderr=subprocess.STDOUT) 

This will run test.py with argument_list as it's command-line parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

This is awesome. Wouldn't have crossed this hurdle without your help. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.