简体   繁体   中英

Calling Python script with arguments from VBscript

I have a Python script with 2 arguments and I would like to run it via VBscript. The problem is when I type command manually in windows command line, it works without a problem. When I want to call the same script from a .vbs file, it doesn't run the .py file. A new command window appears and disappears quickly. The scripts in .vbs is :

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

Note : When I call/run another .py without argument, it is working fine.

尝试将其更改为:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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