我知道如何重定向到文件,并使用tee;在基本水平上。所以
$ alias outanderr='bash -c "echo stdout >&1; echo stderr >&2"'
# A fake "application" displaying both output and error messages.
$ outanderr 1>file # redirect stdout to a file, display stderr
stderr
$ outanderr 2>file # redirect stderr to a file, display stdout
stdout
$ outanderr 1>file 2>&1 # redirect both to a file, display nothing
$ outanderr | tee file; echo "-- file contents --" && cat file
# redirect stdout to a file, display both (note: order is messed up)
stderr
stdout
-- file contents --
stdout
$ outanderr 2>&1 | tee file; echo "-- file contents --" && cat file
# redirect both to a file, display both
stdout
stderr
-- file contents --
stdout
stderr
问题是:用什么代替问号来获得下面的输出:
$ outanderr ???; echo "-- file contents --" && cat file
# redirect both to a file, display stderr
stderr
-- file contents --
stdout
stderr
内容:
- 假设重击。
- 订单应保存在文件中。
- stderr的内容逐行实时显示,即没有缓冲。
- 可以使用单独的脚本文件。
- 魔术可能是必要的。
@Kevin我认为这个问题比这更笼统。在这里,
—
lgeorget 2013年
outanderr
只是一个别名,它在stdout和stderr上打印一行。这个想法(如果可能)是构建一个通用解决方案,该解决方案可以与任何程序一起使用,而无需修改它们。
@lgeorget我理解这一点,但我不认为有可能严格满足通用解决方案中的所有限制,因此我在查看是否可以得到特定解决方案。
—
凯文
@Igeorget是正确的。
—
TWiStErRob
outanderr
您对程序有多少控制权?