Karoline Brynildsen
Karoline Brynildsen

Reputation: 3648

Passing value from vbscript to batch file is not working correctly

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).

Upvotes: 1

Views: 223

Answers (1)

Tomalak
Tomalak

Reputation: 338208

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

Upvotes: 2

Related Questions