2 // MAIN -- a little demo of the capabilities of the "K3Process" class
4 // version 0.2, Aug 2nd 1997
6 // Copyright 1997 Christian Czezatke <e9025461@student.tuwien.ac.at>
10 #include "k3process.h"
14 #include <kaboutdata.h>
15 #include <kcomponentdata.h>
16 #include <QtCore/QCoreApplication>
20 #include "k3processtest.h"
26 // A nice input for "sort"... ;- )
28 static const char txt
[] = "hat\nder\nalte\nhexenmeister\nsich\ndoch\neinmal\nwegbegeben\n\
29 und\nnun\nsollen\nseine\ngeister\nsich\nnach\nmeinem\nwillen\nregen\nseine\nwort\nund\n\
30 werke\nmerkt\nich\nund\nden\nbrauch\nund\nmit\ngeistesstaerke\ntu\nich\nwunder\nauch\n";
33 int main(int argc
, char *argv
[])
35 K3Process p1
, p2
, p3
, p4
;
37 KAboutData
about("kprocesstest", 0, ki18n("kprocesstest"), "version");
38 KComponentData
cData(&about
);
39 //KCmdLineArgs::init(argc, argv, &about);
41 QCoreApplication
app(argc
, argv
);
43 printf("Welcome to the K3Process Demo Application!\n");
46 // The kghostview demo -- Starts a kghostview instance blocking. -- After
47 // kghostview has exited, kghostview is restarted non-blocking. When the process exits,
48 // the signal "processExited" will be emitted.
52 QObject::connect(&p1
, SIGNAL(processExited(K3Process
*)), &dummy
, SLOT(printMessage(K3Process
*)));
54 printf("starting kghostview blocking (close to continue)\n");
55 p1
.start(K3Process::Block
);
56 printf("restarting kghostview non blocking\n");
61 // A konsole with tcsh to demonstrate how to pass command line options to a process
62 // with "K3Process" (is run blocking)
65 printf("Starting konsole with /bin/tcsh as shell (close to continue)\n");
66 p2
<< "konsole" << "-e" << "/bin/tcsh";
67 p2
.setWorkingDirectory("/tmp");
68 QObject::connect(&p2
, SIGNAL(processExited(K3Process
*)), &dummy
, SLOT(printMessage(K3Process
*)));
69 p2
.start(K3Process::Block
);
72 // Getting the output from a process. "ls" with parameter "-l" is called and it output is captured
76 QObject::connect(&p3
, SIGNAL(processExited(K3Process
*)),
77 &dummy
, SLOT(printMessage(K3Process
*)));
79 QObject::connect(&p3
, SIGNAL(receivedStdout(K3Process
*, char *, int)),
80 &dummy
, SLOT(gotOutput(K3Process
*, char *, int)));
81 QObject::connect(&p3
, SIGNAL(receivedStderr(K3Process
*, char *, int)),
82 &dummy
, SLOT(gotOutput(K3Process
*, char *, int)));
84 p3
.start(K3Process::NotifyOnExit
, K3Process::AllOutput
);
88 // An even more advanced example of communicating with a child proces. -- A "sort" command
89 // is started. After it has been started a list of words (as stored in "txt") is written
90 // to its stdin. When the sort command has absorbed all its input it will emit the signal
91 // "inputSent". -- This signal is connected to "outputDone" in the Dummy object.
93 // "OutputDone" will do a "sendEof" to p4. -- This will cause "sort" to perform its task.
94 // The output of sort is then captured once more by connecting to the signal "outputWaiting"
99 QObject::connect(&p4
, SIGNAL(processExited(K3Process
*)),
100 &dummy
, SLOT(printMessage(K3Process
*)));
102 QObject::connect(&p4
, SIGNAL(receivedStdout(K3Process
*, char *, int)),
103 &dummy
, SLOT(gotOutput(K3Process
*, char *, int)));
104 QObject::connect(&p4
, SIGNAL(receivedStderr(K3Process
*, char *, int)),
105 &dummy
, SLOT(gotOutput(K3Process
*, char *, int)));
107 QObject::connect(&p4
, SIGNAL(wroteStdin(K3Process
*)),
108 &dummy
, SLOT(outputDone(K3Process
*)));
110 p4
.start(K3Process::NotifyOnExit
, K3Process::All
);
111 printf("after p4.start");
112 p4
.writeStdin(txt
, strlen(txt
));
114 printf("Entering man Qt event loop -- press <CTRL><C> to abort\n");
117 #include "k3processtest.moc"