Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

Windows Batch Script: Redirect ALL output to a file

I am running various Java benchmarks and would like to archive the results. I execute the (dacapo) benchmark like this:

C:VMjreinjava  -jar C:enchmarksdacapo-9.12-bach.jar %arg1% > %time::=%

I pass the type of benchmark in over a parameter, thats what %arg1% is.

You can see that I am redirecting the output to a textfile. Unfortunately, the first and last line of the output is still printed in the console and not into the textfile:

===== DaCapo 9.12 luindex starting =====
===== DaCapo 9.12 luindex PASSED in 2000 msec =====

Especially the last line would be important to have in the text file :)

Is there a trick to force this behavior?

question from:https://stackoverflow.com/questions/15346863/windows-batch-script-redirect-all-output-to-a-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You must redirect STDOUT and STDERR.

command > logfile 2>&1

STDIN is file descriptor #0, STDOUT is file descriptor #1 and STDERR is file descriptor #2.
Just as "command > file" redirects STDOUT to a file, you may also redirect arbitrary file descriptors to each other. The >& operator redirects between file descriptors. So, 2 >& 1 redirects all STDERR output to STDOUT.

Furthermore, take care to add 2>&1 at the end of the instruction because on Windows, the order of redirection is important as command 2>&1 > logfile will produce an empty file, as Dawid added in the comments.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...