0

I have the following in a Windows batch file

my_app < "%%PARAMETER_FOR_APP" 

The application executes succesfully, and outputs three lines to the console.

I want to capture that output so as to be able to save it to a log file.

I am trying this:

set LOG_FILE_NAME = mylog.log
my_app < "%%PARAMETER_FOR_APP" > COMMAND_OUTPUT
echo %COMMAND_OUTPUT%
echo %COMMAND_OUTPUT% >> %LOG_FILE_NAME%

I am expecting a variable, COMMAND_OUTPUT, to be created, which I can then use with the eccho command. But instead an empty file, COMMAND_OUTPUT, is created on the file system.

What is the correct way to do this?

user1052610
  • 4,048
  • 9
  • 46
  • 88

1 Answers1

0

FOR /F is the standard way to get command output in batch file. In your case you also need to escape the redirection with ^

for /f "tokens=* delims=" %%# in ('my_app ^< "%%PARAMETER_FOR_APP" ') do set "COMMAND_OUTPUT=%%#"

try this.

npocmaka
  • 53,069
  • 18
  • 138
  • 177