Search code examples
batch-filecmdwindows-console

cmd console output to variable


I have some tool which is outputs some data directly to console output.

I want to save this output to some variable and then pass it somewhere else...

Is it possible to do?

Example:

rem this outputs String1 values from myfile.txt
GetString myfile.txt String1
rem I want this value for example in %p% variable, and then:
call MyApp %p%

Solution

  • You can try this

    for /f %%a in ('GetString myfile.txt') do call MyApp %%a
    

    Although I'm not really sure what you mean about the String1 bit, if this isn't right, can you clarify?