I have to write a simple batch script for windows that have to "launch" another script and return only the last line of the output of the launched program.
I need this to catch the "status" of the launched command, that it's printing something like: "End programm with code 0" after many ( and not known number of other line )
What I need is to catch only the last line of myprogram.cmd inside my catch.cmd
I'll try to use CALL inside my catch.cmd script to run myprogram.cmd, but I don't know how to manipulate and get back the last output line.
If I use only CALL myprogram.cmd
I'll get all the output inside my catch.cmd, I'll try with CALL myprogram.cmd >NULL
to hide all the output inside my catch.cmd, but how to get the last line of the myprogram.cmd?
Thanks for any suggestion
I've created two files.
called.bat:
@echo off
dir c:\
caller.bat:
@echo off
for /f "tokens=*" %%f in ('call called.bat') do set lastLine=%%f
echo %lastLine%
Running caller.bat will execute called.bat "in silence" and save the last line in the variable %lastLine%
.
So in your case the anser will be this line:
...
for /f "tokens=*" %%f in ('call myprogram.cmd') do set lastLine=%%f
if "%lastLine%"=="End programm with code 0" (
::DO SOMETHING
)
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.