[英]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. 我是VBScript的新手,正在从python文件执行vbs文件。 Now in the vbs file there is a
String value
which I need to return back to the python file. 现在在vbs文件中有一个
String value
,我需要返回到python文件。 I have tried with WScript.Quit()/ WScript.StdOut()
. 我已经尝试过
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. 还有其他方法可以做到这一点。
If you run your .vbs in the console, ie using CScript.exe
, the you can redirect the output using ">": 如果您在控制台中运行.vbs,即使用
CScript.exe
,则可以使用“>”重定向输出:
CScript example.vbs //NoLogo > output.txt
And inside your .vbs use WScript.StdOut
object with .Write
or .WriteLine
method. 而且里面你的.vbs使用
WScript.StdOut
对象与.Write
或.WriteLine
方法。 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.exe
运行脚本,则...
WScript example2.vbs
...you'll need to write your output to file using FileSystemObject
. ...您需要使用
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.