I have a python code that goes as
for x in name:
print(x)
os.system('exe file')#prints output1
os.system('2nd exe file)#prints output2
it is printing
output1
x
output2
why is it happening?
I have a python code that goes as
for x in name:
print(x)
os.system('exe file')#prints output1
os.system('2nd exe file)#prints output2
it is printing
output1
x
output2
why is it happening?
This has been aswered here. Check answers for ways to solve it.
When you're outputting to a pipe, Python buffers your output that's written to
sys.stdout
and outputs it after a flush, or after it's overflown, or upon closing (when the program exits). While it'll buffer the print calls, system calls output directly into stdout and their output won't be buffered. That's why you're seeing such precedence. To avoid that, usepython -u
:python -u test.py > test.out; cat test.out
See more info here.