[英]Command not working with subprocess.run but does work with subprocess.call
I am trying to use subprocess.run
with a custom argument, that works both directly from windows cmd, and from subprocess.call
, but not with subprocess.run
, as suggested by Running shell command and capturing the output . I am trying to use subprocess.run
with a custom argument, that works both directly from windows cmd, and from subprocess.call
, but not with subprocess.run
, as suggested by Running shell command and capturing the output .
This works:这有效:
retcode = subprocess.call(build_command_line, shell=True)
This fails:这失败了:
result = subprocess.run([build_command_line], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
and outputs和输出
The filename, directory name, or volume label syntax is incorrect.
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "C:\Program Files\Python37\lib\subprocess.py", line 1207, in _execute_child
startupinfo)
File "C:\Program Files\JetBrains\PyCharm 2020.1.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_monkey.py", line 551, in new_CreateProcess
return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
PermissionError: [WinError 5] Access is denied
even though I run with administrator.即使我与管理员一起运行。
Not that it should matter, but for completeness:不是说它应该重要,而是为了完整性:
build_command_line
is: build_command_line
是:
'"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe" "C:\\code\\EPMD\\Kodex\\Solutions\\Kodex.All.sln" /t:REBUILD /p:Configuration=RELEASE'
How do I get it to work with subprocess.run
?如何让它与subprocess.run
一起使用?
Problem was my understanding of subprocess.run
问题是我对subprocess.run
的理解
correct call:正确调用:
result = subprocess.run(build_command_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.