Read output from VBS in CMD scripts

Here is a sample VB script, test.vbs:
  1. wscript.echo "Testoutput"
  2. 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:
  1. @echo off
  2. FOR /F "usebackq delims=" %%i IN (`cscript test.vbs`) DO Set myvar=%%i
  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>