问题
I not that good in programming and have a problem using the subprocess()
command in Python.
My program creates the following string:
wsl ocrmypdf -sr -l deu "\mnt\z\dms\_inbox\Scan 2019-11-27 13.12.33.pdf" "z:\dms\_inbox\OCR_Scan 2019-11-27 13.12.33.pdf"
If I use this command in my Windows 10 DOSbox it is working without issues.
Now I want to start it with the following Python command:
subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, universal_newlines=True).decode()
While cmd
contains the above mentioned string.
The system returns something like command wsl not found
.
What is wrong?
Update. The error message in wing is: The error message in wing is:
File "D:\DMS\MiniDMS.py", line 73, in subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, universal_newlines=True).decode() File "C:\Python\Lib\subprocess.py", line 512, in run raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'C:\Windows\System32\wsl.exe ocrmypdf -sr -l deu \mnt\z\dms_inbox\Scan 2019-11-27 13.12.33.pdf z:\dms_inbox\OCR_Scan 2019-11-27 13.12.33.pdf' returned non-zero exit status 1.
I think there were some quotes missing in the string. So I changed it to
C:\Windows\System32\wsl.exe ocrmypdf -sr -l deu "\mnt\z\dms\_inbox\Scan 2019-11-27 13.12.33.pdf" "z:\dms\_inbox\OCR_Scan 2019-11-27 13.12.33.pdf"
the error output is now:
Der Befehl "C:\Windows\System32\wsl.exe" ist entweder falsch geschrieben oder konnte nicht gefunden werden. which means that the command wsl.exe could not be found (even if it is there...)
回答1:
The reason for this behaviour: wsl.exe is a 64bit application and therefore located in the real system32 folder. As my python installation is a 32bit application, it always refers to the SysWOW64 folder which does not contain the wsl.exe.
The way to solve it: I simply installed python as 64bit application, now it is working.
来源:https://stackoverflow.com/questions/59429146/using-subprocess-in-with-variable-containing-the-dos-cmd