I am trying to send git push
command with subprocess.Popen
. Command is successful but the git command output is returned by subprocess
under stderr
instead off stdout
def execute_cmds(commands):
for cmd in commands:
send_commands = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
shell=True
)
send_commands.wait()
output, errors = send_commands.communicate()
print('OUTPUT: {}'.format(output))
print('ERRORS: {}'.format(errors))
OUTPUT:
ERRORS: warning: redirecting to https://gitlab.com/networkAutomation/git_test_module.git/
To https://gitlab.com/networkAutomation/git_test_module
afb2400..fbcb4db HEAD -> master
这对 Git 来说很正常:Git 将其输出打印到其标准错误流中。
You can set the stderr to the standard output:
stderr=subprocess.STDOUT
so you can get the value returned in stdout
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.