How to use the output of one command as input

February 19, 2011 at 03:58:56
Specs: Windows Vista
Hi,
I want to use output of one command as input to another command in DOS.

Deatails:

My command is: systeminfo | findstr /C:"OS Name"
Output may be any OS, Ex: vista or XP or 7 or 2008

I want to use this output and call files i hv already created.
Ex: vista.bat, xp.bat, etc

If my output from first command comes Windows Vista, then I want to call vista.bat (c:\vista.bat)
and same for others (for XP call xp.bat, for 7 call 7.bat.

Please help me if anybody know how to do this with batch file.


With Best,
San3d


See More: How to use the output of one command as input

Report •


#1
February 19, 2011 at 06:30:23
@echo off & setlocal
for /F "delims=" %%j in ('systeminfo ^| findstr /C:"OS Name"') do set _OS=%%j
if "%_OS%=="XP" call XP
if "%_OS%=="7" call 7
if "%_OS%=="2008" call 2008

By the way this is NT batch more powerful than DOS that doesn't exist in Vista, XP or Seven systems.

Report •

#2
February 23, 2011 at 01:11:34
Thanks IVO.

I changed the file paths as follows:

@echo off & setlocal
for /F "delims=" %%j in ('systeminfo ^| findstr /C:"OS Name"') do set _OS=%%j
if "%_OS%=="Microsoft Windows XP Professional" call c:\XP.txt
if "%_OS%=="7" call c:\7.txt
if "%_OS%=="2008" call c:\2008.txt

But when running the batch file it's showing the error as below:

"Windows was unexpected at this time."

Please reply if you have any idea of this error.
I am running it on Windows XP Pro.


Report •
Related Solutions


Ask Question