test.py
#coding=utf-8 import subprocess compilePopen = subprocess.Popen('gcc haha',shell=True,stderr=subprocess.PIPE) compilePopen.wait() print('the status code is:',compilePopen.returncode) with open('log','w') as object: object.write(compilePopen.stderr.read())
输出:
('the status code is:', 1)
参考:
https://blog.youkuaiyun.com/qq_31331027/article/details/80518348