Skip to content Skip to sidebar Skip to footer

How To Return A String From A Vbscript Which Is Executed From A Python File

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 WSc

Solution 1:

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
EndSub

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
EndSub

Post a Comment for "How To Return A String From A Vbscript Which Is Executed From A Python File"