从VBScript调用带参数的Python脚本

3 投票
1 回答
10941 浏览
提问于 2025-04-18 11:12

我有一个Python脚本,它需要两个参数,我想通过VBscript来运行这个脚本。问题是,当我在Windows命令行手动输入命令时,一切都正常。但是当我想从一个.vbs文件中调用同样的脚本时,它却没有运行这个.py文件。新的命令窗口出现后又很快消失。以下是.vbs中的脚本:

SET oShell = WScript.CreateObject("Wscript.Shell")
currentCommand = "D:\xxxx\xxxxx.py aaaa bbbbbbb"
WScript.echo currentCommand
oShell.run currentCommand,1,True

即使在currentCommand中加上“python”,也没有任何区别。我还尝试过这样:

SET oShell = WScript.CreateObject("Wscript.Shell")
Dim source_code_path
source_code_path = "D:\xxxx\xxxxx.py" 
Dim variable1 
variable1 = "aaaa"
Dim variable2 
variable2 = "bbbbbbb"
Dim currentCommand 
currentCommand = source_code_path & " " & variable1 & " " & variable2 
WScript.echo currentCommand
oShell.run currentCommand,1,True

我该如何从.vbs文件中调用/运行带有多个参数的.py文件呢?

注意:当我调用/运行另一个没有参数的.py文件时,它是正常工作的。

1 个回答

3

试着把它改成:

currentCommand = "cmd /c " & Chr(34) & source_code_path & " " & variable1 & " " & variable2 & Chr(34)

撰写回答