I have just a script that prints some kind of message to the console,
#!/usr/bin/python import sys print >>sys.stdout, "1 stdout" print >>sys.stderr, "2 stderr"
normal sequence
[ dyno@cola :codes]$ ./x.py 1 stdout 2 stderr [ dyno@cola :codes]$ ./x.py 2>&1 1 stdout 2 stderr
wrong output order
[ dyno@cola :codes]$ ./x.py &>x.txt [ dyno@cola :codes]$ cat x.txt 2 stderr 1 stdout [ dyno@cola :codes]$ ./x.py 2>&1 | tee x.log 2 stderr 1 stdout
It seems that adding sys.stdout.flush() might solve the problem, is there a way to force the message sequence (redirect the output / error to a file) without changing the script?
source share