运行一些运行Python脚本的shell脚本,当重定向到tee或文件时,我会得到stdout行的重新排序。
例如,如果运行shell脚本并将输出输出到我的stdout,则输出如下:
Line1: Starting X
Line2: Output of X
Line3: Starting Y
Line4: Output of Y但是,如果我运行相同的脚本并将输出重定向到文件,或者使用tee,那么来自底层Python脚本的print语句将在执行的最后被打印出来。
Line1: Output of X
Line2: Output of Y
Line3: Starting X
Line4: Starting Y有什么我能避免的吗?
发布于 2016-10-19 17:15:24
它可能是Python脚本同时写入stdout和stderr,而您只重定向其中一个(到一个文件或通过tee)。
若要检查输出的内容,请执行以下操作:
./myscript 2>/dev/null # shows only stdout
./myscript >/dev/null # shows only stderr改变这两个方面的方向:
./myscript >myfile 2>&1 # both to myfile
./myscript |& tee ... # both through teehttps://serverfault.com/questions/809922
复制相似问题