Is there a way to redirect the output of stderr from the command line running at the Windows command line?

I have a program for which I want to automate runs as it takes a while to complete. For some reason, it outputs everything to stderr instead of stdout and I would like to check its progress, so I need to redirect the output of stderr in the run command.

I've tried this:

start "My_Program" "C:\Users\Me\my_program.exe" --some --presets --for 
--my_program.exe --output "C:\Users\Me\output_file_for_my_program" 
"C:\Users\Me\input_file_for_my_program" 2>"C:\Users\Me\my_program_output.log"

      

But it turns out that the redirect is picked up from the beginning, so I end up with a 0-byte file with the result start

- namely, nothing. Is there a way to make the output redirect somehow tied to the output of my_program?

I've experimented with escaping and neither ^2>

nor 2^>

does it work. Any help would be greatly appreciated!

+2


source to share


4 answers


Try the following:

start "My_Program" "%SystemRoot%\System32\cmd.exe" /c ""C:\Users\Me\my_program.exe" --some --presets --for --my_program.exe --output "C:\Users\Me\output_file_for_my_program" "C:\Users\Me\input_file_for_my_program" 2>"C:\Users\Me\my_program_output.log""

      



Obviously, without having "My Program" here, I cannot verify this as such. If we assume that the built-in "FIND.EXE" command returns "File not found - filename" on STDERR, the following works for me:

start "My_Program" "%SystemRoot%\System32\cmd.exe" /c "find /v /i "blarg" "c:\not a real file.txt" 2> C:\stderr.txt"

      

+4


source


Use the / B switch. No new window is created and redirections remain, but the command runs in the background as needed.

start /B test.bat >test.txt <nul

      



test.bat:

@echo off
echo bbb
sleep 10
echo ccc
exit

      

+3


source


How do I enable invoking your command with a redirect in a batch file and using a run in a batch file?

+2


source


I used the following command and it worked:

start / affinity 2 / wait cmd.exe / C parameter myprog.exe parameter1 1 ^>. \ a.log 2 →. \ b.log

Link: http://www.pcreview.co.uk/forums/redirect-standard-output-w-start-command-t1467634.html

Abhishek

+2


source







All Articles