Note that there are some explanatory texts on larger screens.

plurals
  1. POExecuting a vbs file with arguments created by python
    primarykey
    data
    text
    <p>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 different sheets with the help of a python code. I have the following 2 versions of the python code:</p> <p>Version 1:</p> <pre><code>import os import sys import subprocess FolderName=sys.argv[1] FileList=os.listdir(FolderName) NewList=[] for i in FileList: NewItem=i.split('.xls') NewXls=FolderName+"\\"+NewItem[0]+".xlsx " NewCsv=FolderName+"\\"+NewItem[0]+".csv" NewCommand="C:\\Users\\user\\XlsToCsv.vbs "+sys.argv[2]+" "+NewXls+NewCsv subprocess.call(NewCommand) </code></pre> <p>Version 2:</p> <pre><code>import os import sys import subprocess def main(directory,extension,sheet): for filename in os.listdir(directory): if filename.endswith(extension): path = os.path.join(directory, filename) base = os.path.join(directory, filename[:len(filename)-len(extension)]) print base new_xls = base + extension new_csv = base + '.csv' subprocess.call(['C:\\Users\\user\\XlsToCsv.vbs', sheet, new_xls, new_csv]) main(sys.argv[1],sys.argv[2],sys.argv[3]) </code></pre> <p>It does not matter, which I try, I get the same error message:</p> <pre><code> Traceback (most recent call last): File "C:/Users/user/Desktop/Work/XlsDir.py", line 16, in &lt;module&gt; subprocess.call(NewCommand) File "C:\Python27\lib\subprocess.py", line 524, in call return Popen(*popenargs, **kwargs).wait() File "C:\Python27\lib\subprocess.py", line 711, in __init__ errread, errwrite) File "C:\Python27\lib\subprocess.py", line 948, in _execute_child startupinfo) WindowsError: [Error 193] %1 er ikke et gyldigt Win32-program </code></pre> <p>The last line of the error message means approximately, that it is not a valid Win32-program.</p> <p>What I have tried so far:</p> <ul> <li>If I run the .vbs file from command prompt with the right arguments (sheet, name of the .xls file and name of the .csv file) then it works fine.</li> <li>If I print the commands that python generates and copy them into command prompt, they work fine.</li> <li>I tried every combinations of '\' and '\' within the different paths, and nothing got any better.</li> <li>I tried to execute the programs with replacing the sys.argv[i] arguments with specific arguments and then execute the .py file from command prompt. I get the same error message.</li> </ul> <p>I hope some of you can help me. Thanks a lot!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload