开发者

saving stdout, stderr and both into 3 separate files

开发者 https://www.devze.com 2023-03-22 03:13 出处:网络
I am using ksh. On this link http://www.shelldorad开发者_StackOverflow中文版o.com/shelltips/advanced.html#redir , there is an example for saving stdout, stderr and both into 3 separate files.

I am using ksh. On this link http://www.shelldorad开发者_StackOverflow中文版o.com/shelltips/advanced.html#redir , there is an example for saving stdout, stderr and both into 3 separate files.

((./program 2>&1 1>&3 | tee ~/err.txt) 3>&1 1>&2 | tee ~/out.txt) > ~/mix.txt 2>&1

I tried that but I am getting below error:

ksh: syntax error: `(' unexpected

Please advice.


Pretty much works for me:

$ ksh
$ ps | grep "$$"
 6987 pts/6    00:00:00 ksh
$ cat program.sh
#!/bin/sh

echo "err" 1>&2
echo "out"
$ ((./program.sh 2>&1 1>&3 | tee err.txt) 3>&1 1>&2 | tee out.txt) > mix.txt 2>&1
$ cat out.txt
out
$ cat err.txt
err
$ cat mix.txt
err
out
0

精彩评论

暂无评论...
验证码 换一张
取 消