Executing a vbs file with arguments created by python

后端 未结 2 1290
故里飘歌
故里飘歌 2020-12-10 07:04

I would like to convert dozens of excel sheets to csv files at once. I have a working .vbs file which makes the conversion, and I would like to execute this .vbs file on the

2条回答
  •  时光取名叫无心
    2020-12-10 07:57

    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
    

提交回复
热议问题