Redirect batch stderr to file

Posted by nivlam on Stack Overflow See other posts from Stack Overflow or by nivlam
Published on 2009-05-28T00:24:04Z Indexed on 2010/03/13 5:05 UTC
Read the original article Hit count: 638

Filed under:
|
|

I have a batch file that executes a java application. I'm trying to modify it so that whenever an exception occurs, it'll write the STDERR out to a file.

It looks something like this:

start java something.jar method %1 %2 2>> log.txt

Is there a way I can write the arguments %1 and %2 to the log.txt file as well? I don't want to write it to the log file everytime this batch file gets called, only when an exception occurs.

I tried searching for a way to redirect STDERR into a variable, but I couldn't figure it out. Ideally I'd like the log file to look something like:

Batch file called with parameters:
- "first arg"
- "second arg"
Exception: 
java.io.exception etc...

------------------------------------

Batch file called with parameters:
- "first arg"
- "second arg"
Exception: 
java.io.exception etc...

© Stack Overflow or respective owner

Related posts about Windows

Related posts about batch