1

I have written a batch file that runs a vbscript and then collects the values from the vbscrit for further process.

This is my code:

myBatch.bat

@ECHO OFF
setlocal EnableDelayedExpansion

REM ECHO ============= RUNNING BATCH =============
ECHO. 

for /F "delims=" %%a in ('CSCRIPT C:\myVBScript.vbs') do (
    ECHO RESULT: %%a
   )


REM ECHO ============= FINNISHED BATCH =============
ECHO. 

myVBScript.vbs

    Option Explicit
Dim values, splitStr


    'ask for value
    values=InputBox("Please provide a list separated by semicolon","Do stuff","item1;item2") 
    splitStr=Split(values,";")

    If UBound(splitStr) >= 1 Then
        WScript.Echo splitStr(0)
        WScript.Echo splitStr(1)
    End If

And this is the output:

RESULT: Microsoft (R) Windows Script Host Version 5.8

RESULT: Copyright (C) Microsoft Corporation. All rights reserved.

RESULT: item1

RESULT: item2

Where does the two first lines come from and how can I avoid them? This is very annoing and I cant figure out how to just get the actual values (item1 and item2).

4
  • 1
    General question, why would you want to use batch script to process the output from VBScript? Given that batch is distinctly less capable than VBScript in this department you should consider using VBScript all the way. Commented Apr 24, 2015 at 12:36
  • Becuase this is deep down inside an existing application, and since I opened a batch file and vbscript for the frist time yesterday I do not feel confident to make major changes in the existing project. Commented Apr 24, 2015 at 12:50
  • Fair enough. But if you spend time studying how to do certain things, keep in mind that given the choice between batch and VBS, that time is better spent on studying VBS. Commented Apr 24, 2015 at 12:52
  • The other (less recommendable) answer would have been to use the skip paramter to for, like in for /F "skip=2 delims=" %%a in ... Commented Apr 24, 2015 at 13:05

1 Answer 1

2

The two lines

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

are a banner that is automatically printed by the interpreter cscript.exe.

Use the nologo parameter

cscript //nologo C:\myVBScript.vbs

to avoid the banner in the script's output.

You can also make nologo the default for your user by running the following command once:

cscript //nologo //s
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you! I knew the answer should be simple
@Ansger: What are the doubles slashes for?
@Tomalak Parameters with single slashes are passed to the script. Parameters for the interpreter have double slashes. See cscript //?.
@Ansgar Single slashes have always worked (and continue to work) very well for me. I usually give the parameters to cscript before and the parameters to the script after the the script name.
@Tomalak Hmm... it seems double slashes are indeed optional when you pass the interpreter arguments before the script. I never bothered checking before.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.