您发布的代码似乎没有明显错误,并且对我有用。
这是我的测试文件和输出:
生成文件:
clean:
@echo 'SHELL:' $(SHELL)
check_uboot:
@echo 'ADDR:' $(LINUX_ETH_ADDR)
测试.py:
from PyQt4 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.button = QtGui.QPushButton('Test', self)
self.button.clicked.connect(self.handleButton)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.button)
self.process = QtCore.QProcess(self)
def handleButton(self):
env = QtCore.QProcessEnvironment.systemEnvironment()
env.insert("LINUX_ETH_ADDR", "3c:98:bf:00:00:f4")
self.process.setProcessEnvironment(env)
self.process.readyReadStandardOutput.connect(self.readReady)
self.process.start("make", ("clean", "check_uboot"))
def readReady(self):
print str(self.process.readAllStandardOutput())
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
输出:
$ python2 test.py
SHELL: /bin/sh
ADDR: 3c:98:bf:00:00:f4