如何从从python文件执行的vbscript返回字符串 [英] How to return a string from a vbscript which is executed from a python file

查看:26
本文介绍了如何从从python文件执行的vbscript返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 VBScript 的新手,正在从 python 文件执行 vbs 文件.现在在 vbs 文件中有一个 String value 我需要返回到 python 文件.我试过 WScript.Quit()/WScript.StdOut() .但似乎他们不支持字符串.'因为存在类型不匹配错误.

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.

推荐答案

如果您在控制台中运行 .vbs,即使用 CScript.exe,您可以使用>"重定向输出:

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

在你的 .vbs 中使用 WScript.StdOut 对象和 .Write.WriteLine 方法.例如:

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

但是如果你用 WScript.exe 运行你的脚本...

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

WScript example2.vbs

...您需要使用 FileSystemObject 将输出写入文件.

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

这篇关于如何从从python文件执行的vbscript返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆