-1

I can do

$./a.out 1>stdout_file 2>stderr_file

But then i dont see anything on the screen. Or I can do

$./a.out | tee log.log

But then stdout and stderr goes to the same file.

How can I achieve both?

drdot
  • 3,215
  • 9
  • 46
  • 81

1 Answers1

2

Does this work for you? (I assume you're using bash as you're on Linux, not sure about other shells):

./a.out 1> >(tee stdout.log) 2> >(tee stderr.log)
tink
  • 14,342
  • 4
  • 46
  • 50
  • 2
    Note that this isn't completely without side effects: Ordering is no longer guaranteed (you can have a program print line-A to stderr followed by line-B to stdout, f/e, but have the stdout line actually reach the console first). – Charles Duffy Dec 04 '18 at 23:19
  • Can you elaborate how it works? – drdot Dec 04 '18 at 23:20
  • 2
    @drdot, the syntax in question is process substitution, discussed in detail at http://wiki.bash-hackers.org/syntax/expansion/proc_subst – Charles Duffy Dec 04 '18 at 23:21