【问题标题】:Calling Python script with arguments from VBscript使用来自 VBscript 的参数调用 Python 脚本
【发布时间】:2014-06-26 15:05:28
【问题描述】:

我有一个带有 2 个参数的 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 时,它工作正常。

【问题讨论】:

  • 我的命令也有效。这部分是我的错误。谢谢。

标签: python vbscript


【解决方案1】:

尝试将其更改为:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多