2

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.

sorin
  • 8,016
  • 24
  • 79
  • 103

5 Answers5

4

In Linux, you can use the tee utility.

In Windows, PowerShell contains a tee cmdlet. For cmd, you will need to download and install a separate utility.

blueadept
  • 516
  • 2
  • 6
1

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.

David Z
  • 5,475
  • 2
  • 25
  • 22
1

Linux: command | tee logfile

Windows: Install cygwin, then run: command | tee logfile

MikeyB
  • 39,291
  • 10
  • 105
  • 189
0

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.

ChrisF
  • 1,871
  • 1
  • 21
  • 28
0

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).

Pat
  • 185
  • 7