简体   繁体   English

使用来自VBscript的参数调用Python脚本

[英]Calling Python script with arguments from VBscript

I have a Python script with 2 arguments and I would like to run it via VBscript. 我有一个带2个参数的Python脚本,我想通过VBscript运行它。 The problem is when I type command manually in windows command line, it works without a problem. 问题是当我在Windows命令行中手动键入命令时,它可以正常工作。 When I want to call the same script from a .vbs file, it doesn't run the .py file. 当我想从.vbs文件调用相同的脚本时,它不会运行.py文件。 A new command window appears and disappears quickly. 一个新的命令窗口出现并迅速消失。 The scripts in .vbs is : .vbs中的脚本是:

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

There is no difference when add "python" to currentCommand. 将“ python”添加到currentCommand时没有区别。 I also tried like this: 我也这样尝试过:

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

How can I call/run .py file with several arguments from .vbs file? 如何使用.vbs文件中的多个参数调用/运行.py文件?

Note : When I call/run another .py without argument, it is working fine. 注意:当我调用/运行另一个不带参数的.py时,它工作正常。

尝试将其更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM