[英]Python subprocess.checkoutput Called Process Error
In the windows command line, I enter the follow command to enable a windows feature: 在Windows命令行中,我输入以下命令以启用Windows功能:
>dism.exe -online -Enable-Feature -FeatureName:MSMQ-HTTP
This command works just fine and enables the MSMQ-HTTP feature. 该命令可以正常工作并启用MSMQ-HTTP功能。 Now I'm writing a Python script to automate this process, my code 现在,我正在编写一个Python脚本来自动化该过程,我的代码
subprocess.check_output(['dism.exe', '-online', '-Enable-Feature', '-FeatureName:MSMQ-HTTP'], shell=True)
returns a nasty error, CalledProcessError: Command '['dism.exe', '-online', '-Enable-Feature', '-FeatureName:MSMQ-HTTP']' returned non-zero exit status 11. 返回一个讨厌的错误,CalledProcessError:命令'['dism.exe','-online','-Enable-Feature','-FeatureName:MSMQ-HTTP']'返回非零退出状态11。
Can anyone shed some light as to why this isn't working? 任何人都可以阐明为什么它不起作用吗?
There were some bitness issues going on with Python's subprocess module and DISM.exe. Python的子流程模块和DISM.exe发生了一些位问题。 Even when specifying the C:\\Windows\\system32\\dism.exe absolute path I was getting Error Code 11. 即使指定C:\\ Windows \\ system32 \\ dism.exe绝对路径,我也收到错误代码11。
My eventual solution was to write a 10 line batch file: 我最终的解决方案是编写一个10行批处理文件:
@echo off
if EXIST %WINDIR%\system32\dism.exe (
set DISM=%WINDIR%\system32\dism.exe
)
if EXIST %WINDIR%\SysNative\dism.exe (
set DISM=%WINDIR%\SysNative\dism.exe
)
%DISM% -online -Enable-Feature -FeatureName:MSMQ-ADIntegration
%DISM% -online -Enable-Feature -FeatureName:MSMQ-HTTP
%DISM% -online -Enable-Feature -FeatureName:MSMQ-Triggers
This little batch file is called from my Python script via subprocess: 这个小批处理文件通过子进程从我的Python脚本中调用:
def MSMQ():
p = subprocess.Popen(r"PrereqInstall\SetMSMQFeatures.bat", shell=True)
stout, stderr = p.communicate()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.