Executing a vbs file with arguments created by python

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

Leave a Comment