FBB::CinInserter(3bobcat) | Executing Child Processes | FBB::CinInserter(3bobcat) |
FBB::CinInserter - Runs external programs reading standard input
#include <bobcat/cininserter>
Linking option: -lbobcat
The FBB::CinInserter class offers a basic interface for calling external programs (so-called child processes) reading their standard input streams. The standard output and standard error streams of the child processes by default are not handled by CinInserter objects. The child’s standard input is provided through the CinInserter object: information inserted into an CinInserter object is forwarded to the child process’s standard input stream. The PATH environment variable is not used when calling child processes: child process programs must be specified using paths.
CinInserter objects may repeatedly be used to execute the same or different child processes. Before starting the next child process, the current child process must have finished.
Arguments passed to child processes may be surrounded by double or single quotes. Arguments surrounded by double quotes have their double quotes removed, while interpreting any escape-sequences that may have been used within. Arguments surrounded by single quotes have their single quotes removed, while accepting their content as-is. In addition unquoted escape-sequences may be specified: those escape sequences are evaluated and replaced by their intended characters (e.g., \100 is converted to @).
When information of undetermined size or structure must be inserted into a child process then the child process cannot determine when to stop. This creates an interesting problem: the child process starts, and the parent process must wait until its child process has finished processing its input. But input can only be forwarded to the child’s input stream after the child process has started. To solve this problem InterterFork offers an overloaded execute member, passing information to the child process via a separate thread.
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
FBB::Exec (private), FBB::OFdBuf (private), std::ostream.
Copy and move constructors (and assignment operators) are not available.
The destructor ends the CinInserter’s child process, if it is still active.
//#include <bobcat/cininserter> #include "../cininserter" #include <iostream> #include <fstream> using namespace std; using namespace FBB; int main() {
CinInserter inserter;
inserter.execute("/bin/cat");
ifstream in("build");
inserter << in.rdbuf();
cout << "child returns: " << inserter.stop() << ’\n’;
inserter.execute("/bin/cat");
in.seekg(0); // reset to the beginning
inserter << in.rdbuf();
// when immediately followed by another execute, ’stop’ is optional
inserter.execute("/bin/cat", "a simple text\n");
inserter.execute("/bin/cat", "a simple text\n");
bool bret = inserter.execute("/bin/cat", "a simple text\n");
cout << "direct string insertion: " << bret << ’\n’; }
bobcat/cininserter - provides the class interface
bobcat(7), cerrextractor(3bobcat), coutextractor(3bobcat), execl(3), exec(3bobcat), fork(3bobcat), pipe(3bobcat), process(3bobcat), stdextractor(3bobcat).
None reported.
Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.
This is free software, distributed under the terms of the GNU General Public License (GPL).
Frank B. Brokken (f.b.brokken@rug.nl).
2005-2022 | libbobcat-dev_6.02.02 |