diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kdecore/tests/kprocesstest.cpp | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdecore/tests/kprocesstest.cpp')
-rw-r--r-- | kdecore/tests/kprocesstest.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/kdecore/tests/kprocesstest.cpp b/kdecore/tests/kprocesstest.cpp new file mode 100644 index 000000000..79769a90d --- /dev/null +++ b/kdecore/tests/kprocesstest.cpp @@ -0,0 +1,116 @@ +// +// MAIN -- a little demo of the capabilities of the "KProcess" class +// +// version 0.2, Aug 2nd 1997 +// $Id$ +// +// (C) Christian Czezatke +// e9025461@student.tuwien.ac.at +// + + +#include "kprocess.h" + +#include <stdio.h> +#include <string.h> +#include <kapplication.h> + +#include <signal.h> + +#include "kprocesstest.h" + +#define PROCNO 10 + + +// +// A nice input for "sort"... ;- ) +// +static const char txt[] = "hat\nder\nalte\nhexenmeister\nsich\ndoch\neinmal\nwegbegeben\n\ +und\nnun\nsollen\nseine\ngeister\nsich\nnach\nmeinem\nwillen\nregen\nseine\nwort\nund\n\ +werke\nmerkt\nich\nund\nden\nbrauch\nund\nmit\ngeistesstaerke\ntu\nich\nwunder\nauch\n"; + + +int main(int argc, char *argv[]) +{ + KProcess p1, p2, p3, p4; + Dummy dummy; + KApplication app(argc, argv, "kprocesstest"); + + + printf("Welcome to the KProcess Demo Application!\n"); + + // + // The kghostview demo -- Starts a kghostview instance blocking. -- After + // kghostview has exited, kghostview is restarted non-blocking. When the process exits, + // the signal "processExited" will be emitted. + // + + p1 << "kghostview"; + QObject::connect(&p1, SIGNAL(processExited(KProcess *)), &dummy, SLOT(printMessage(KProcess *))); + + printf("starting kghostview blocking (close to continue)\n"); + p1.start(KProcess::Block); + printf("restarting kghostview non blocking\n"); + p1.start(); + + + // + // A konsole with tcsh to demonstrate how to pass command line options to a process + // with "KProcess" (is run blocking) + // + + printf("Starting konsole with /bin/tcsh as shell (close to continue)\n"); + p2 << "konsole" << "-e" << "/bin/tcsh"; + p2.setWorkingDirectory("/tmp"); + QObject::connect(&p2, SIGNAL(processExited(KProcess *)), &dummy, SLOT(printMessage(KProcess *))); + p2.start(KProcess::Block); + + // + // Getting the output from a process. "ls" with parameter "-l" is called and it output is captured + // + + p3 << "ls" << "-l"; + QObject::connect(&p3, SIGNAL(processExited(KProcess *)), + &dummy, SLOT(printMessage(KProcess *))); + + QObject::connect(&p3, SIGNAL(receivedStdout(KProcess *, char *, int)), + &dummy, SLOT(gotOutput(KProcess *, char *, int))); + QObject::connect(&p3, SIGNAL(receivedStderr(KProcess *, char *, int)), + &dummy, SLOT(gotOutput(KProcess *, char *, int))); + + p3.start(KProcess::NotifyOnExit, KProcess::AllOutput); + + + // + // An even more advanced example of communicating with a child proces. -- A "sort" command + // is started. After it has been started a list of words (as stored in "txt") is written + // to its stdin. When the sort command has absorbed all its input it will emit the signal + // "inputSent". -- This signal is connected to "outputDone" in the Dummy object. + // + // "OutputDone" will do a "sendEof" to p4. -- This will cause "sort" to perform its task. + // The output of sort is then captured once more by connecting to the signal "outputWaiting" + // + // + + p4 << "sort"; + QObject::connect(&p4, SIGNAL(processExited(KProcess *)), + &dummy, SLOT(printMessage(KProcess *))); + + QObject::connect(&p4, SIGNAL(receivedStdout(KProcess *, char *, int)), + &dummy, SLOT(gotOutput(KProcess *, char *, int))); + QObject::connect(&p4, SIGNAL(receivedStderr(KProcess *, char *, int)), + &dummy, SLOT(gotOutput(KProcess *, char *, int))); + + QObject::connect(&p4, SIGNAL(wroteStdin(KProcess *)), + &dummy, SLOT(outputDone(KProcess *))); + + p4.start(KProcess::NotifyOnExit, KProcess::All); + printf("after p4.start"); + p4.writeStdin(txt, strlen(txt)); + + printf("Entering man Qt event loop -- press <CTRL><C> to abort\n"); + app.exec(); + + return 0; +} +#include "kprocesstest.moc" |