0

The question says it all. Is there any way I can have standard output appear on my terminal screen and get inputted into a file as well?

I use tcsh on Linux.

NeutronStar
  • 2,057
  • 7
  • 31
  • 49

1 Answers1

1
$command | tee $output_file

man tee for more information.

Tripp Kinetics
  • 5,178
  • 2
  • 23
  • 37
  • What if my `$command` is an executable I made with C? I want the results of the `printf()` functions in my code to display on the terminal and go to the output file. Does `tee` work for that? – NeutronStar May 13 '14 at 20:57
  • Yup. Anything that goes to `stdout` gets sent to `stdout` as well as the file. – Tripp Kinetics May 13 '14 at 20:58
  • Well, there is added complexity if you want to do thing like redirect `stderr`, but in those kinds of cases, I would highly recommend using a Bourne-style shell rather than a C-shell derivative. – Tripp Kinetics May 13 '14 at 21:00
  • I'm trying it and it doesn't work. Does it work with `nohup`? I am also using `nohup`. – NeutronStar May 13 '14 at 21:00
  • It should. Try it on any different shell. C-shells don't lend themselves very easily to this sort of thing. Perhaps something simple like sh or ksh? Hold on. Installing tcsh. – Tripp Kinetics May 13 '14 at 21:13
  • `nohup ls -l | tee blong.out` works fine here under `tcsh`. – Tripp Kinetics May 13 '14 at 21:15