AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
AsyncFw::SystemProcess Class Reference

The SystemProcess class. More...

#include <AsyncFw/SystemProcess>

Collaboration diagram for AsyncFw::SystemProcess:
[legend]

Public Types

enum  State : uint8_t {
  None , Running , Finished , Crashed ,
  Error
}
 

Public Member Functions

 SystemProcess (bool=false)
 
bool start (const std::string &, const std::vector< std::string > &={})
 
bool start ()
 
State state ()
 
pid_t pid ()
 
void wait ()
 
int exitCode ()
 
bool input (const std::string &) const
 

Static Public Member Functions

template<typename T>
static bool exec (const std::string &cmd, const std::vector< std::string > &args, T f)
 
template<typename T>
static bool exec (const std::string &cmd, T f)
 
static bool exec (const std::string &cmd, const std::vector< std::string > &args={})
 

Public Attributes

FunctionConnectorProtected< SystemProcess >::Connector< State > stateChanged {AbstractFunctionConnector::Queued}
 The FunctionConnector for SystemProcess stateChanged.
 
FunctionConnectorProtected< SystemProcess >::Connector< const std::string &, bool > output {AbstractFunctionConnector::Queued}
 The FunctionConnector for SystemProcess output.
 

Detailed Description

The SystemProcess class.

Warning
Unix-like systems only

Example:

#include <AsyncFw/MainThread>
#include <AsyncFw/SystemProcess>
#include <AsyncFw/Timer>
#include <AsyncFw/LogStream>
int main(int argc, char *argv[]) {
process.output([](const std::string &str, bool err) {
if (!err) logInfo() << "OUT:" << '\n' + str;
else { logError() << "ERR:" << '\n' + str; }
});
process.stateChanged([](AsyncFw::SystemProcess::State _s) {
if (_s == AsyncFw::SystemProcess::Running) return;
AsyncFw::MainThread::exit(0);
});
process.start("/bin/bash");
AsyncFw::Timer::single(50, [&process]() { process.input("echo 1234567890\n"); });
AsyncFw::Timer::single(100, [&process]() { process.input("_cmd_\n"); }); //error: _cmd_ not found
AsyncFw::Timer::single(150, [&process]() { process.input("ls /\n"); });
AsyncFw::Timer::single(200, [&process]() { process.input("exit\n"); });
logNotice() << "Start Applicaiton";
int ret = AsyncFw::MainThread::exec();
return ret;
}
Examples
SystemProcess/main.cpp.

The documentation for this class was generated from the following files: