Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3: os.system not redirecting stdout

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.

like image 606
mewais Avatar asked Sep 04 '26 02:09

mewais


1 Answers

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

like image 75
Alexandr Shurigin Avatar answered Sep 05 '26 17:09

Alexandr Shurigin