cmd - Putting output file into var -
i have easy .bat file
%2 >file.tmp set /p %1=<file.tmp
i expect use script in way:
putvar var1 command.bat
it should first line of output command.bat variable var1 , after should able use var1 variable, example
putvar var1 command.bat echo %var1%
unfortunately not work. how work? maybe there easier way?
your problem in sample code command running (command.bat
) batch file, being invoked inside batch file, , if batch file call batch file without using call
command, execution not return caller batch.
to keep syntax, can use
(cmd /c "%~2")>file.tmp set /p "%~1="<file.tmp
spawning second instance of cmd
handle command, redirecting output temporary file , reading file (only first line of command.bat
output) variable.
a simpler way of doing use for /f
for /f "delims=" %%a in ('%~2') set "%~1=%%a"
which, more or less, same work. run command retrieve output and, in case, iterate on output of command, assigning each of lines of command.bat
output variable. obviously, last line stored inside variable, loop overwrite value in each iteration.
Comments
Post a Comment