0

I would like to run (launche in cmd):

java -server -Xms1024m -Xmx4096m -XX:PermSize=256m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -jar FTBServer-1.7.10-1272.jar nogui

and redirect the output to the screen and a file, I got this to work but I also would like a totally separate file for errors but these errors also need to showup in the log file.

So I got this to redirect normal output: echo %test% 1>> D:\Documenten\Bureaublad\test.txt
and 2>>&1 to add the errors.

If I would add 2>> D:\Documenten\Bureaublad\test2.txt the errors won't show up in the first file.

This i what I got in total:

@echo off
SET /P test=give input
echo %test% 1>> D:\Documenten\Bureaublad\test.txt 2>> D:\Documenten\Bureaublad\test2.txt 2>>&1
pause

it works but puts the output only to the file and not the screen and doesn't put the errors in the first and second file, only in the first.

dbenham
  • 127,446
  • 28
  • 251
  • 390
Lenny
  • 27
  • 8

1 Answers1

1

You cannot do what you are asking. A given file handle (stderr in this case) can only be redirected once. The last specification wins when multiple redirections are put on the same command.

There is no way to send stderr to a file, and then somehow merge it into the stdout stream properly - the combined output will be scrambled. The best you can do is to merge stdout and stderr into one stream, pipe it into tee to write the combined output to to a file, and then use another pipe to pass the output through FINDSTR to somehow filter out only error messages and redirect to its own file. If you cannot identify error messages by the content, then you are out of luck.

Tee is not a standard command for batch, so you will need a 3rd party port. Or you could use my hybrid JScript/batch TEE.BAT that is pure script that runs natively on any Windows machine from XP onward.

For demonstration, I will assume each of your error messages appears on a single line and starts with the word Error:. You will have to adapt the search string to properly identify the errors in your output.

yourCommand 2>&1 | tee.bat output.log | findstr "^Error:" >output.err
Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Thanks for the help but is there a way to write it to a file and the screen or do I run in the same problem? – Lenny Mar 02 '15 at 14:56
  • @Lenny - Same issues when writing the output to the screen. Just eliminate the final redirection in my proposed solution. – dbenham Mar 02 '15 at 15:52