Reputation: 1337
As mentioned in the title. I have this in my code:
os.system("./vpr/vpr " + config + " " + file_name + " --seed " + str(seed) + " &> " + str(bench_name) + "-" + str(seed) + ".stdout")
Which has a lot of variables, but it simply evaluates to this (I know for sure because I have a print statement right before the os.system
line):
./vpr/vpr vpr/k6_N10_40nm.xml vpr/blif/clma.blif --seed 0 &> clma-0.stdout
The command actually runs fine, but the redirection does not! The file clma-0.stdout
gets created but remains empty, and I still get the entire stdout on my terminal.
What is the solution for that? What am I doing wrong? I'm using python-3.7 on Ubuntu 19.10
Thanks.
Upvotes: 3
Views: 752
Reputation: 32987
I'm not sure why exactly, but it seems like os.system
is using Dash (Ubuntu's default scripting shell), not Bash, so &>
is not supported. What happens instead is the command is backgrounded, and the file is truncated. That is, command &> filename
is equivalent to command &; > filename
.
To fix it you could simply use the equivalent redirection, > filename 2>&1
.
Upvotes: 3
Reputation: 3981
I think that's because you are trying to do it using system command, not Bash which supports these I/O redirection flags.
Try this one with shell=True
https://docs.python.org/2/library/subprocess.html#subprocess.call
Upvotes: 3