我可以同时输出stdout
和stderr
控制台屏幕和存储他们中的一个上到日志文件?
我写了一个测试shell脚本:
#!/bin/sh
echo OUT! >&1
echo ERR! >&2
Run Code Online (Sandbox Code Playgroud)
我可以通过运行脚本在屏幕上输出它们:
$./test
OUT!
ERR!
Run Code Online (Sandbox Code Playgroud)
我可以通过以下方式输出stderr
并捕获stdout
到日志文件中:
$./test | tee 1>log
ERR!
$cat log
OUT!
Run Code Online (Sandbox Code Playgroud)
我只能通过以下方式输出所有内容stdout
并stderro
输入日志文件:
$./test 2>&1| tee 1>log
$cat log
OUT!
ERR!
Run Code Online (Sandbox Code Playgroud)
我可以通过以下方式输出stdout
和stderr
并将它们全部捕获到日志文件中:
$./test 2>&1 | tee log
OUT!
ERR!
$cat log
OUT!
ERR!
Run Code Online (Sandbox Code Playgroud)
我可以通过以下方式输出两者都可以捕获stdout
到日志文件中:
$./test | tee 2>&1 log
ERR!
OUT!
$cat log
OUT!
Run Code Online (Sandbox Code Playgroud)
我的问题是:
stdout
并捕获stderr
到文件中?(我试过./test|tee 2>log …
我知道如果我把&
应用程序放在终端的末尾,它会在后台运行并且终端仍然可以接收命令,例如:
howchen@host:~
-> cutecom&
[1] 17269
howchen@host:~
Run Code Online (Sandbox Code Playgroud)
它可以弹出cutecom
应用程序。但是,我需要用 root 运行这个应用程序,我不能输入:
howchen@host:~
-> su cutecom&
Run Code Online (Sandbox Code Playgroud)
如果我以前从未运行过某些应用程序su
,它将输出如下:
howchen@host:~
-> su cutecom&
[1] 17404
howchen@host:~
-> No passwd entry for user 'cutecom'
Run Code Online (Sandbox Code Playgroud)