在包含 DOS-cmd 的变量中使用 subprocess() [英] Using subprocess() in with variable containing the DOS-cmd
问题描述
我不太擅长编程,并且在 Python 中使用 subprocess()
命令时遇到问题.我的程序创建以下字符串:
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"
如果我在 Windows 10 DOSbox 中使用此命令,它可以正常工作.
If I use this command in my Windows 10 DOSbox it is working without issues.
现在我想使用以下 Python 命令启动它:
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()
虽然 cmd
包含上述字符串.
While cmd
contains the above mentioned string.
系统返回类似command wsl not found
之类的东西.
The system returns something like command wsl not found
.
怎么了?
更新.翼中的错误消息是:wing中的错误信息是:
Update. The error message in wing is: The error message in wing is:
文件D:\DMS\MiniDMS.py",第 73 行,在 subprocess.run(cmd,shell=True,check=True,stdout=subprocess.PIPE,Universal_newlines=True).decode() 文件 "C:\Python\Lib\subprocess.py",第 512 行,在运行中引发 CalledProcessError(retcode, process.args,
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.exeocrmypdf -sr -l deu \mnt\z\dms_inbox\Scan 2019-11-27 13.12.33.pdfz:\dms_inbox\OCR_Scan 2019-11-27 13.12.33.pdf' 返回非零退出状态 1.
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"
错误输出现在是:
Der Befehl "C:\Windows\System32\wsl.exe" is entweder falschgeschrieben oder konnte nicht gefunden werden.这意味着无法找到命令 wsl.exe(即使它在那里...)
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...)
推荐答案
这种行为的原因:wsl.exe 是一个 64 位应用程序,因此位于真正的 system32 文件夹中.由于我的python安装是一个32位的应用程序,它总是指向不包含wsl.exe的SysWOW64文件夹.
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.
解决方法:我只是将python安装为64位应用程序,现在它可以工作了.
The way to solve it: I simply installed python as 64bit application, now it is working.
这篇关于在包含 DOS-cmd 的变量中使用 subprocess()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!