Keef Baker
Keef Baker

Reputation: 641

How to pass arguments to subprocess.call

learning python to replace bash here and I've tried to generate an argument and pass it to subprocess.call. Tried a couple of ways but it only ever seems to run the first section. as an example:

#!/usr/bin/python
import subprocess
command='ls -l'
dibner='scum.py'
commands=[command, dibner]
subprocess.call(commands,shell=True)

logically I thought this would call ls -l scum.py but it seems to just call ls -l. Any idea what I'm doing wrong here?

Upvotes: 0

Views: 1412

Answers (1)

falsetru
falsetru

Reputation: 369074

You need to pass ls, -l separately.

...
command = ['ls', '-l']
dibner = 'scum.py'
commands = comamnd + [dibner]
...

Otherwise, ls -l instead of ls is interpreted as a command.

Upvotes: 2

Related Questions