![](/img/trans.png)
[英]Why does subprocess.run not read new lines yet subprocess.call does?
[英]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 .
這有效:
retcode = subprocess.call(build_command_line, shell=True)
這失敗了:
result = subprocess.run([build_command_line], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
和輸出
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
即使我與管理員一起運行。
不是說它應該重要,而是為了完整性:
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'
如何讓它與subprocess.run
一起使用?
問題是我對subprocess.run
的理解
正確調用:
result = subprocess.run(build_command_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.