Search code examples
bashhttp-redirectpipestdoutstderr

cmd1, cmd2 connect with pipe and save log each commad


I'm going to pipe command 1 and command 2. And the log of that command wants to output to one file.

but log display on terminal...

$cmd1 1> result1.out 2> log.txt

$cmd2 result1.out 1> result2.out 2>> log.txt

Two commands can be used as a pipe to reduce time.

Each run causes about an hour's difference from the one used by connecting to a pipe.

$cmd1 | cmd2 1> result.out 2> log.txt 

this situation i want to save all log to log.txt but log didn't write that file


Solution

  • Group the pipeline and redirects the stderr of the whole group:

    { cmd1 | cmd2 >result.out; } 2>log.txt