1 | #include <QFile>
|
---|
2 | #include <QDebug>
|
---|
3 | #include <QProcess>
|
---|
4 |
|
---|
5 | int main (int argc, char *argv[])
|
---|
6 | {
|
---|
7 | if (argc < 4)
|
---|
8 | {
|
---|
9 | qDebug("Usage: %s <in_file> <out_file> <child> [<child_arguments>]\n\n"
|
---|
10 | "Sends <in_file> to stdin of <child> and puts its stdout to"
|
---|
11 | "<out_file>.", argv [0]);
|
---|
12 | return 0;
|
---|
13 | }
|
---|
14 |
|
---|
15 | QByteArray data;
|
---|
16 |
|
---|
17 | QFile qfIn (argv [1]);
|
---|
18 | if (qfIn.open (QIODevice::ReadOnly))
|
---|
19 | {
|
---|
20 | data = qfIn.readAll();
|
---|
21 | qfIn.close();
|
---|
22 | qDebug() << "Read" << data.size() << "bytes from" << argv [1];
|
---|
23 | }
|
---|
24 | else
|
---|
25 | {
|
---|
26 | qDebug() << "Couldn't open" << argv [1] << "for reading";
|
---|
27 | return 1;
|
---|
28 | }
|
---|
29 |
|
---|
30 | qint64 bytes;
|
---|
31 | QProcess proc;
|
---|
32 |
|
---|
33 | #if 0
|
---|
34 | proc.setProcessChannelMode (QProcess::ForwardedChannels);
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | QStringList args;
|
---|
38 | for (int i = 4; i < argc; ++ i)
|
---|
39 | args << argv [i];
|
---|
40 |
|
---|
41 | proc.start (argv [3], args, QIODevice::ReadWrite);
|
---|
42 |
|
---|
43 | if (!proc.waitForStarted())
|
---|
44 | {
|
---|
45 | qDebug() << "Failed to start" << argv [3] <<":" << proc.errorString();
|
---|
46 | return 1;
|
---|
|
---|