Details
Description
If QProcess' write buffer has some data before start(), it will be
send to the new process.
I'm not sure if it is by design or not, but there seems no way to discard
them so that the new process can start fresh after error exit of the
last process.
// think that this is server process and it dies while communicating qDebug() << "-- server #0 starting --"; proc.start("sleep 0.1"); proc.waitForStarted(); for (int i = 0; i < 10000; i++) // large enough to make them buffered proc.write("hello world\n"); proc.waitForFinished(); // remainder of IPC message is still kept in write buffer of QProcess. // main process want to discard it, but it seems not possible. qDebug() << "-- server #0 died --"; qDebug() << "error:" << proc.error() << "(4: WriteError)"; qDebug() << "bytesToWrite:" << proc.bytesToWrite(); proc.close(); qDebug() << "bytesToWrite (after close):" << proc.bytesToWrite(); // main process notices the server died, so restarts it. the new server // process receives the remainder of the last message, which would cause // sort of communication protocol error. qDebug() << "-- server #1 starting --"; proc.start("wc -c"); proc.waitForStarted(); proc.closeWriteChannel(); proc.waitForFinished(); qDebug() << "received:" << proc.readLine() << "[bytes]";
Attached the code to reproduce this problem.