Upon closer inspection, it appears that the stdout from 7z isn't returned to the calling process until the archiving operation has finished.

Therefore, PyQt4 is probably not to blame for the below scenario.  If these new findings are incorrect, I'll post another message once I've received confirmation.



Chris Giles wrote, On 24/09/06 18:27:
Dear PyKDE Members

I'm opening a new QThread which launches a command-line archiver (7z) in a QProcess (called 'pArc').

I'm using following code block within that thread:
while not pArc.waitForFinished(250) :
    if pArc.waitForReadyRead(100) :
        sArcData = QtCore.QString(pArc.readData(512))
        print "Output = " + str(sArcData)
    else :
        print "Nothing"

While the (large) files are being archived, "Nothing" is printed to the screen several times.  When the process is finished, "Output = ..." is then printed.  However, I know that 7z prints data to its stdout while the archiving process is happening (i.e. it doesn't just wait until it has finished).  I want to update a QProgressBar based on the output from 7z, so I can't wait until it has finished otherwise this defeats the purpose of the QProgressBar.

The PyQt4 documentation has this to say:
You also have the option of forwarding the output of the running process to the calling, main process, by passing ForwardedChannels as the argument.

QProcess.ForwardedChannels: QProcess forwards the output of the running process onto the main process. Anything the child process writes to its standard output and standard error will be written to the standard output and standard error of the main process.

So, I then added this line before the above code block:
pArc.setReadChannelMode(QtCore.QProcess.ForwardedChannels)

While the file is being archived, I can now correctly see the standard output being progressively printed to the screen.  But how do I read this output since it is no longer associated with my QProcess?  How
do I access the standard output of this 'main' process?

Thanks for your help.


Chris

_______________________________________________
PyKDE mailing list    [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to