python - 如何从从 python 文件执行的 vbscript 返回字符串

标签 python vbscript

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

有没有其他方法可以做到这一点。

最佳答案

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

CScript example.vbs //NoLogo > output.txt

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

' example.vbs
Main

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

但是如果您使用 WScript.exe 运行脚本...

WScript example2.vbs

...您需要使用 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 - 如何从从 python 文件执行的 vbscript 返回字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15129085/

相关文章:

python - 为什么这个 forloop 会跳过列表中的项目?

python - 将大写字母移动到字符串前面并将小写字母大写的函数?

excel - 使用 VBScript 以独占模式打开 Excel 文件

vbscript - 在ASP脚本中使用wscript.shell时无法引用UNC路径?

Python+Tkinter,如何在独立于tk前端的后台运行?

python - IndexError : only integers, 切片 (`:` ),省略号 (`...` ),是有效索引

asp-classic - 经典 ASP 中的线程 sleep ?

mysql - 存储json,双引号转义问题

vbscript - 服务器端注释:ASP Classic中的<%--%>等效项是什么?

python - 字节命令功能不适用于 PySerial