2

I am new to VBScript and am executing a vbs file from python file. Now in the vbs file there is a String value which I need to return back to the python file. I have tried with WScript.Quit()/ WScript.StdOut() . But it seems they don't support Strings. 'coz there is a Type mismatch error.

Is there any other way to do that.

1 Answer 1

4

If you run your .vbs in the console, i.e. using CScript.exe, the you can redirect the output using ">":

CScript example.vbs //NoLogo > output.txt

And inside your .vbs use WScript.StdOut object with .Write or .WriteLine method. For example:

' example.vbs
Main

Sub Main()
    Dim result
    result = 1 / Cos(25)
    WScript.StdOut.Write result
End Sub

But if you run your script with WScript.exe...

WScript example2.vbs

...you'll need to write your output to file using FileSystemObject.

' example2.vbs
Main

Sub Main()
    Dim result, fso, fs
    result = 1 / Cos(25)
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fs  = fso.CreateTextFile("output.txt", True)
    fs.Write result
    fs.Close
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah i think I have to write it in a file

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.