#include #include #include int main (int argc, char *argv[]) { if (argc < 4) { qDebug("Usage: %s []\n\n" "Sends to stdin of and puts its stdout to" ".", argv [0]); return 0; } QByteArray data; QFile qfIn (argv [1]); if (qfIn.open (QIODevice::ReadOnly)) { data = qfIn.readAll(); qfIn.close(); qDebug() << "Read" << data.size() << "bytes from" << argv [1]; } else { qDebug() << "Couldn't open" << argv [1] << "for reading"; return 1; } qint64 bytes; QProcess proc; #if 0 proc.setProcessChannelMode (QProcess::ForwardedChannels); #endif QStringList args; for (int i = 4; i < argc; ++ i) args << argv [i]; proc.start (argv [3], args, QIODevice::ReadWrite); if (!proc.waitForStarted()) { qDebug() << "Failed to start" << argv [3] <<":" << proc.errorString(); return 1; } qDebug() << "Started" << argv [3]; bytes = proc.write (data); qDebug() << "Wrote" << bytes << "bytes to child process"; proc.closeWriteChannel(); qDebug() << "Waiting for child termination..."; if (!proc.waitForFinished()) { qDebug() << "Child ended abnormally:" << proc.errorString(); } else { qDebug() << "Child ended normally"; } data = proc.readAllStandardOutput(); qDebug() << "Read" << data.size() << "bytes from child process"; QFile qfOut (argv [2]); if (qfOut.open (QIODevice::WriteOnly)) { bytes = qfOut.write(data); qfOut.close(); qDebug() << "Wrote" << bytes << "bytes to" << argv [2]; } else { qDebug() << "Couldn't open" << argv [2] << "for writing"; return 1; } qDebug() << "Done."; return 0; }