Thanks all. In addition to your solutions, the reason none of my tests worked is that I had somehow messed up my Python installation and python.exe was missing. (No, I have no idea how either!) I finally tried a test using subprocess.POpen(['python', ...) and got an error. Reinstalled python 2.6 and all is good now, except for an error involving pydevd that may be unavoidable. I am confused as to why QProcess didn't produce any stderror output about my missing python.exe.
The same code saved to a .py file and imported to the Script Editor didn't produce any output from the QProcess. I guess that's because the QProcess was a child of the main module, and the module was destroyed after the line myTest.run() I also tried running Justin's blocking.py<https://gist.github.com/justinfx/3949647> in Maya, and it instantly crashed Maya, so I moved its guts into a simple example Maya window I found, and it works! So, here's the simplest example of QProcess that I got working within Maya: (Apologies if this is not the appropriate way to post code here...please let me know if I should do it differently in any way. I haven't looked into gist.github yet.) import subprocess import sip import maya.OpenMayaUI as mui from PyQt4 import QtCore, QtGui def getMainWindow(): pointer = mui.MQtUtil.mainWindow() return sip.wrapinstance(long(pointer), QtCore.QObject) class BlockingTestWin(QtGui.QMainWindow): def __init__(self, parent=None): super(BlockingTestWin, self).__init__(parent) self.mainWidget = QtGui.QWidget() self.setCentralWidget(self.mainWidget) #Main layout self.layout = QtGui.QVBoxLayout() self.mainWidget.setLayout(self.layout) self.blocking_button = QtGui.QPushButton("Block") self.blocking_button.clicked.connect(self.blocking) self.layout.addWidget(self.blocking_button) self.signal_button = QtGui.QPushButton("Signals") self.signal_button.clicked.connect(self.non_blocking) self.layout.addWidget(self.signal_button) self.output = QtGui.QLineEdit() self.layout.addWidget(self.output) self.clear_button = QtGui.QPushButton("Clear") self.clear_button.clicked.connect(self.output.clear) self.layout.addWidget(self.clear_button) def finished(self, returnCode): self.setMessage("Return code: %s" % returnCode) def setMessage(self, msg): print msg self.output.setText(msg) def blocking(self): self.setMessage("Starting blocking sleep") process = subprocess.Popen(['python', '-c', 'import time\ntime.sleep(5)']) ret = process.wait() self.finished(ret) def non_blocking(self): self.setMessage("Starting non blocking sleep") process = QtCore.QProcess(parent=self) process.setProcessChannelMode(process.ForwardedChannels) process.finished.connect(self.finished) process.start('python', ['-c', 'import time\ntime.sleep(5)']) def run(): app = BlockingTestWin(getMainWindow()) app.show() On Tuesday, 14 January 2014 03:44:43 UTC+11, Ævar Guðmundsson wrote: > > If you run into further troubles, try explicitly directing your output the > the pipe buffer you want ( Maya uses both ) > > print >> sys.stdout, "finished qprocess" > print >> sys.__stdout__, "finished qprocess" > > Justin's method is better, just leaving this one as a note for further > experimentation, hope it helps and all that. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3fbd4c03-409f-4594-bb57-8ab9509d93dc%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
