fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kde3support / tests / k3processtest.cpp
blob919c7ea4a84f7533b43b3784de5a81ba8da18b13
1 //
2 // MAIN -- a little demo of the capabilities of the "K3Process" class
3 //
4 // version 0.2, Aug 2nd 1997
5 //
6 // Copyright 1997 Christian Czezatke <e9025461@student.tuwien.ac.at>
7 //
10 #include "k3process.h"
12 #include <stdio.h>
13 #include <string.h>
14 #include <kaboutdata.h>
15 #include <kcomponentdata.h>
16 #include <QtCore/QCoreApplication>
18 #include <signal.h>
20 #include "k3processtest.h"
22 #define PROCNO 10
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;
36 Dummy dummy;
37 KAboutData about("kprocesstest", 0, ki18n("kprocesstest"), "version");
38 KComponentData cData(&about);
39 //KCmdLineArgs::init(argc, argv, &about);
40 //KApplication app;
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.
51 p1 << "kghostview";
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");
57 p1.start();
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
75 p3 << "ls" << "-l";
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"
98 p4 << "sort";
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");
115 return app.exec();
117 #include "k3processtest.moc"