Executing a vbs file with arguments created by python

懵懂的女人 提交于 2019-11-28 11:39:33

To elaborate on Ansgar's remedy:

Starting a .vbs from the command line 'works', because the shell associates the extension .vbs with an application (e.g. cscript/wscript; see ftype, assoc, cscript //E, cescript //S).

subprocess.call() does not open a shell, so either specify the application (c|wscript.exe) or start the shell yourself:

import subprocess

#subprocess.call("notepad") # works

#subprocess.call("dir") # [Error 2] The system cannot find the file specified
                        # no shell, no intrinsics

#subprocess.call("19112944.vbs") # [Error 193] %1 is not a valid Win32 application
                                 # no shell, can't associate .vbs with c|wscript.exe

subprocess.call("cscript 19112944.vbs") # works

subprocess.call("cmd /c 19112944.vbs") # works
                                       # have shell, can associate .vbs with c|wscript.exe

Try running the script with cscript.exe:

subprocess.call(['cscript.exe', 'C:\\Users\\user\\XlsToCsv.vbs', sheet, new_xls, new_csv])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!