我可以使用以下方法重定向stdout和stderr分隔文件:
dir >> out 2>> error
Run Code Online (Sandbox Code Playgroud)
或stderror与stdout一起使用的单个文件:
dir >> consolidate 2>&1
Run Code Online (Sandbox Code Playgroud)
我怎么能一起做这个(出去,错误,一次合并文件)?
您可以尝试以下方式:
(command > >(tee out.txt) 2> >(tee error.txt >&2)) &> consol.txt
Run Code Online (Sandbox Code Playgroud)
测试:
$ ls
f
Run Code Online (Sandbox Code Playgroud)
$ ls g*
ls: cannot access g*: No such file or directory
Run Code Online (Sandbox Code Playgroud)
$ (ls g f > >(tee out.txt) 2> >(tee error.txt >&2)) &> consol.txt
Run Code Online (Sandbox Code Playgroud)
$ cat out.txt
f
Run Code Online (Sandbox Code Playgroud)
$ cat error.txt
ls: cannot access g: No such file or directory
Run Code Online (Sandbox Code Playgroud)
$ cat consol.txt
f
ls: cannot access g: No such file or directory
Run Code Online (Sandbox Code Playgroud)