AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
SystemProcess/main.cpp

SystemProcess example

Warning
Unix-like systems only
/*
Copyright (c) 2026 Alexandr Kuzmuk
This file is part of the AsyncFw project. Licensed under the MIT License.
See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
*/
#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;
}
The SystemProcess class.
Definition SystemProcess.h:16
FunctionConnectorProtected< SystemProcess >::Connector< State > stateChanged
The FunctionConnector for SystemProcess stateChanged.
Definition SystemProcess.h:30
FunctionConnectorProtected< SystemProcess >::Connector< const std::string &, bool > output
The FunctionConnector for SystemProcess output.
Definition SystemProcess.h:32
static void single(int ms, T function)
Starts a single shot timer with the specified timeout.
Definition Timer.h:19