0

I was wondering if there's any possible way to save the output of a shell script while to a file while it's running in terminal. for example, say I'm compiling a java program with the command javac foo.java. How would I save all the output of that particular command (errors, etc.) to a file for future reference without having to hit command- s and select save and replace after every time I run the command?

dakatk
  • 99
  • 1
  • 1
  • 13

3 Answers3

2

Use javac foo.java > output.txt to capture the output of your command to the file output.txt.

This will however hide all output from you while it is compiling your module.

If you would like to see the output of your build in the terminal and at the same time capture the output into file output.txt you can use tee:

javac foo.java | tee output.txt

The tee program reads from stdin and writes everything into the specified file and also to stdout again.

Johannes Overmann
  • 4,914
  • 22
  • 38
1

Is that what you want ?

javac foo.java > output.txt

All error will go in the output.txt and nothing will print on the shell.

jrjc
  • 21,103
  • 9
  • 64
  • 78
1

I use tee

javac foo.java | tee output.log

similar to this thread.

Dump terminal session to file?

Community
  • 1
  • 1
jcalloway
  • 1,155
  • 1
  • 15
  • 24