Last active
July 11, 2019 11:02
-
-
Save justinfx/5174795 to your computer and use it in GitHub Desktop.
Revisions
-
justinfx revised this gist
Mar 16, 2013 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ #!/bin/bash for i in {1..5} do echo "Progress: $i" sleep 1 done -
justinfx created this gist
Mar 16, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ from functools import partial from subprocess import Popen, PIPE from PyQt4 import QtCore, QtGui ## testProgram.sh """ #!/bin/bash for i in {1..5} do echo "Progress: $i" sleep 1 done """ COMMAND = "/path/to/testProgram.sh " def started(): print "Started!" def finished(): QtGui.qApp.quit() ### 1) QProcess ### def dataReady(p): print str(p.readAllStandardOutput()).strip() def main(): process = QtCore.QProcess() process.started.connect(started) process.readyReadStandardOutput.connect(partial(dataReady, process)) process.finished.connect(finished) # start it some time after the event loop QtCore.QTimer.singleShot(100, partial(process.start, COMMAND)) ### 2) Subprocess ### def process(): started() process = Popen([COMMAND], stdout=PIPE) while True: line = process.stdout.readline() if not line: break QtGui.qApp.processEvents() print line.strip() finished() def main2(): # start it some time after the event loop QtCore.QTimer.singleShot(100, process) if __name__ == "__main__": app = QtGui.QApplication([]) main() # main2() app.exec_()