i've got a script, that contains a list - the list is just some args that I want to pass to subprocess.run
like this
commands = ["bash command 1", "bash command 2",..]
here is my code
commands = ["bash command 1", "bash command 2",..]
process = subprocess.run([commands], stdout = subprocess.PIPE, shell = True)
how can I pass a list to my subprocess.run?
this is the Traceback
Traceback (most recent call last):
File "./retesting.py", line 18, in <module>
process = subprocess.run([commands], stdout = subprocess.PIPE, shell = True)
File "/usr/lib/python3.5/subprocess.py", line 383, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1221, in _execute_child
restore_signals, start_new_session, preexec_fn)
TypeError: Can't convert 'list' object to str implicitly
I Have no idea what I'm doing wrong and I tried all sorts of things, so I'd appreciate really any help
set
(using{}
) when you need a list (using[]
)?[]
from.run([commands],
.shell=True
. It changes how the command list is interpreted.