I am puzzled by the order of execution of python command and shell command (from subprocess).
For example, I've got a simple code:
import subprocess import shlex command="echo 'test'" arg=shlex.split(command) with open("out.txt", "w") as f: f.write("line1\n") subprocess.call(arg, stdout=f) f.write("line3\n")
I expect out.txt to be:
line1 test line3
However, the actual out.txt is:
test line1 line3
Could somebody explain the reason? Thank you.