I want to save a program's output (stdout) to a file but still be able to see the output on the screen in realtime.
I need a solutions for both Linux and Windows.
I want to save a program's output (stdout) to a file but still be able to see the output on the screen in realtime.
I need a solutions for both Linux and Windows.
On Linux and similar systems:
program | tee filename
The tee
program sends anything that comes into its standard input to its standard output (like cat
) and also writes it to the specified file.
Another way to get the same effect would be
program >filename 2>/dev/null &
tail -f filename
This runs the program in the background, redirecting its standard output to the file, then tail -f
lets you follow data being written to the file in real time (or nearly so, maybe a fraction of a second delay). The 2>/dev/null
makes the standard error stream disappear so that it doesn't interfere with the output of tail -f
.
Linux: command | tee logfile
Windows: Install cygwin, then run: command | tee logfile
For Windows you can do this:
dir > directory.txt & type directory.txt
where you'd replace dir
by your application.
If the output scrolls too fast use:
dir > c:\directory.txt & type c:\directory.txt | more
However, I don't think this would display the contents of the file in real time. You'd have to wait until the process had finished.
In Windows, you can use tee
if you download the GnuWin32 version of it. It's the same as the linux app and comes from the coreutils package.
One word of caution, though: tee
has its own return code, so you won't be able to notice errors from the process piped to it (unless you're in linux, then there are ways around it).