Read output from VBS in CMD scripts
Here is a sample VB script, test.vbs:
- wscript.echo "Testoutput"
- wscript.echo "This is a test"
The strings echoed from the VBS script can be read from a calling CMD script, with a standard FOR loop using the options
/F and
delims as follows, test.cmd:
- @echo off
- FOR /F "usebackq delims=" %%i IN (`cscript test.vbs`) DO Set myvar=%%i
- echo Srcipt result = "%myvar%"
Notice that only the last line echoed from the VB script is stored. If you want to store multiple lines, use the FOR loop
token option also. See
Get date in Windows CMS script for an example.
This entry was posted in
Batch. Bookmark the
permalink.