#include <iostream>
using namespace std;
void handleOutput(const char *buf, int cnt)
{
cout << buf;
}
void handleExit(Exec *exec)
{
cout << "Exited(\"" << exec->command() << "\"): ";
if (exec->ifExited())
{
cout << "exit_status=" << exec->exitStatus();
}
else if (exec->ifSignaled())
{
cout << "term_sig=" << exec->termSig();
}
cout << endl;
}
int main()
{
CppApplication app;
Exec cat("/bin/cat -n");
cat.stdoutData.connect(sigc::ptr_fun(handleOutput));
cat.stderrData.connect(sigc::ptr_fun(handleOutput));
cat.exited.connect(sigc::bind(sigc::ptr_fun(handleExit), &cat));
cat.nice();
cat.run();
cat.writeStdin("Hello, Exec!\n");
cat.writeStdin("This is a test\n");
cat.closeStdin();
Exec xyz("/bin/xyz");
xyz.exited.connect(sigc::bind(sigc::ptr_fun(handleExit), &xyz));
xyz.run();
Exec kill("/bin/sort");
kill.exited.connect(sigc::bind(sigc::ptr_fun(handleExit), &kill));
kill.setTimeout(1);
kill.run();
Exec sleep("/bin/sleep 2");
sleep.exited.connect(sigc::bind(sigc::ptr_fun(handleExit), &sleep));
sleep.exited.connect(mem_fun(app, &CppApplication::quit));
sleep.run();
app.exec();
return 0;
}
The core class for writing asyncronous cpp applications.
Execute external commands.
Contains a single shot or periodic timer that emits a signal on timeout.
Namespace for the asynchronous programming classes.