In python, when I execute the commands
cmd = ['head', '-7', 'rres17.txt', '>', 'x']
subprocess.run(cmd)
I get the error message
head: cannot open ‘>’ for reading: No such file or directory
head: cannot open ‘x’ for reading: No such file or directory
When I execute the command
cmd = "head -7 rres17.txt > x"
subprocess.run(cmd)
I get the error message
FileNotFoundError: [Errno 2] No such file or directory: 'head -7 rres17.txt > x'
I'm using python version 3.5.2. How do I get subprocess to correctly execute this command, the way the documentation seems to indicate that it should? Thanks.
EDIT:
The following commands worked:
cmd = ['head', '-7', 'rres17.txt']
with open("x", "wb") as out: subprocess.Popen(cmd, stdout=out)
Thanks everyone.