Capture output of other program in batch

December 15, 2010 at 07:37:39
Specs: Windows 7
Hell all,
I have to capture the output of other program(isprintvl) in batch and comapre with the string, if it matches do step1, else do step 2.
the output of isprintvl need to be compared with this string "Interstage Application Server Standard-J Edition V9.1.0", if matches set some value, else set another value
Here is the code iam trying to do.

@echo off
setlocal
if CALL isprintvl == "Interstage Application Server Standard-J Edition V9.1.0" (
echo in if
set LINKS_PATH=%IS_HOME%\IDE\eclipse\links
)
else(
echo in else
set LINKS_PATH=%IS_HOME%/../\IDE\0902\eclipse\links
)
Can anybody help please? thanlks, mai


See More: Capture output of other program in batch

Report •


#1
December 15, 2010 at 15:32:11
Well, if I understand well you need to capture the standard output from another BATCH or program to use it into your batch, am I right? Well, if that is the case you could use a FOR with the ENABLEEXTENSIONS option from SETLOCAL. So, for example, let's think about two batch files: One of them uses the echo command to print a couple of messages and the other executes the BATCH from a FOR and captures the message:
=================================================
output_test.bat
=================================================
@echo off
SETLOCAL ENABLEEXTENSIONS
ECHO Hello World!
ECHO Bye World!
ENDLOCAL
EXIT /B 0

================================================
capture_output.bat
================================================
@echo off
SETLOCAL ENABLEEXTENSIONS
FOR /F "delims=" %%a in ('output_test.bat') DO (
echo Output captured: %%a
)

ENDLOCAL
EXIT /B 0

=================================================
You should get and exit like this at executing the later batch:

C:\>capture_output
Output captured: Hello World!
Output captured: Bye World!

C:\>
====================================================

I hope it'll help you


Report •

#2
December 15, 2010 at 16:21:58
Thanks ..davidgpv .
Iam trying to do exactly and i just passed that step..
but iam not able to compare the two variables after that step.

Here is the code iam trying to do :

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS

set DEFAULT_VERSION=Interstage Application Server Standard-J Edition V9.1.0

For /F "tokens=* delims=" %%A in ('CALL isprintvl') Do Set INSTALLED_VERSION=%%A
Echo %INSTALLED_VERSION%
Echo %DEFAULT_VERSION%

if "%INSTALLED_VERSION%" == %DEFAULT_VERSION% (
echo in if condition
set LINKS_PATH=%IS_HOME%\IDE\eclipse\links
)
) else (
echo in else condition
set LINKS_PATH=%IS_HOME%/../\IDE\0902\eclipse\links
)

The output iam getting is :
Interstage Application Server Standard-J Edition V9.1.0
Interstage Application Server Standard-J Edition V9.1.0
in if condition
in else condition

The control is going to if and else also..intresting to me...i tried lot of ways with EQU also..the result is same..

as the two compare string values are same i expect to go in if condition alone, but donno..it is going to else also..is something wrong in compare..??
Could you please help on this issue..Appreciate it..

thanks,
mai


Report •

#3
December 16, 2010 at 07:49:14
Well, seems like Razor2.3 already found the issue in your batch in another thread. Just erase the extra ')' .

Report •

Related Solutions

#4
December 16, 2010 at 08:03:03
Sorry, i typed it wrong..this is what iam trying to do..
setLocal EnableDelayedExpansion


if "%EZFROOT%" == "" echo Environment variable EZFROOT is not set. & goto _ERR1
if "%IS_HOME%" == "" echo Environment variable IS_HOME is not set. & goto _ERR1

set DEFAULT_VERSION=Interstage Application Server Standard-J Edition V9.1.0

For /F "tokens=* delims=" %%A in ('CALL isprintvl') Do Set INSTALLED_VERSION=%%A
Echo Installed Interstage Version is: %INSTALLED_VERSION%
pause
Echo %INSTALLED_VERSION%
Echo %DEFAULT_VERSION%
pause

if "%INSTALLED_VERSION%"==%DEFAULT_VERSION% (
echo in if condition
) else (
echo in else condition
)

the output iam getting is :

Installed Interstage Version is: Interstage Application Server Standard-J Editio
n V9.1.0
Press any key to continue . . .
Interstage Application Server Standard-J Edition V9.1.0
Interstage Application Server Standard-J Edition V9.1.0
Press any key to continue . . .
in if condition
in else condition

.. this call to other program is giving me -- Interstage Application Server Standard-J Edition V9.1.0.
I expect it should go in if condition...


Report •


Ask Question