Reputation: 641
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
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