#include <iostream>
using namespace std;
void handleOutput(const char *buf, int cnt)
{
cout << buf;
}
void handleExit(
Exec *exec)
{
cout <<
"Exited(\"" << exec->
command() <<
"\"): ";
{
}
{
cout <<
"term_sig=" << exec->
termSig();
}
cout << endl;
}
int main()
{
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();
xyz.exited.connect(sigc::bind(sigc::ptr_fun(handleExit), &xyz));
xyz.run();
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();
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.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
Execute external commands.
int exitStatus(void) const
Read the exit code of the subprocess.
const std::string & command(void) const
Get the command name for the command.
bool ifExited(void) const
Check if the subprocess exited in a normal way.
int termSig(void) const
Read the UNIX signal number that caused the subprocess to stop.
bool ifSignaled(void) const
Check if the subprocess exited due to receiving a UNIX signal.
Namespace for the asynchronous programming classes.