Jan-08-2017, 05:42 PM
Hello guys,
I've been experimenting with the subprocess library in python 3.5 on linux.
I've been able to run a few commands with success, but when it comes to run more than one commands at a time, I
don't seem to able to do it. Take a look at this code :
Thank you for reading this.
I've been experimenting with the subprocess library in python 3.5 on linux.
I've been able to run a few commands with success, but when it comes to run more than one commands at a time, I
don't seem to able to do it. Take a look at this code :
import subprocess, shlex command1 = 'ls -laZ > file1.txt' args = shlex.split(command1) #print (args) final = subprocess.Popen(args)I can run the command ls with its arguments fine, but when I want to redirect the output with > to a a new file (file1) I get the following errors :
Error:['ls', '-laZ', '>', 'file1.txt']
ls: cannot access '>': No such file or directory
ls: cannot access 'file1.txt': No such file or directory
I've already tried to use shell=True, but it has no affect. In conclusion is there a way to run several commands at once with subprocess lib instead of just one (with or not its arguments) ? Thank you for reading this.