logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

FBB::CoutExtractor - Runs external programs writing standard output

Author

       Frank B. Brokken (f.b.brokken@rug.nl).

libbobcat-dev_6.07.01                               2005-2025                        FBB::CoutExtractor(3bobcat)

Bobcat

       Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.

Bobcat Project Files

       o      https://fbb-git.gitlab.io/bobcat/: gitlab project page;

       Debian Bobcat project files:

       o      libbobcat6: debian package containing the shared library, changelog and copyright note;

       o      libbobcat-dev:  debian package containing the static library, headers, manual pages, and developer
              info;

Bugs

       None reported.

Constructor

       o      CoutExtractor(size_tbufSize=100):
              A  bufSize  argument  may  be  specified:  it  defines  the  internal  buffer  size  used  by  the
              CoutExtractor’s streambuf. By default the stdandard input  and  standard  error  streams  are  not
              handled.

       o      CoutExtractor(Modemode,size_tbufSize=100):
              The  mode  argument  must  be  CoutExtractor::CLOSE_STD.  It indicates that the standard input and
              standard error streams are redirected to /dev/null: the child processes cannot read their standard
              input streams and any standard error output generated by child processes  is  ignored.  A  bufSize
              argument  may  be  specified:  it  defines  the  internal  buffer  size  used by the CinInserter’s
              streambuf.

       Copy and move constructors (and assignment operators) are not available.

Description

       The  FBB::CoutExtractor  class  offers  a  basic interface for calling external programs (so-called childprocesses) writing their standard output streams. The standard input and standard error  streams  of  the
       child  processes by default are not handled by CoutExtractor objects. The child’s standard output is read
       through the CoutExtractor object: information written by the child process to its standard output  stream
       is  extracted  or  read from CoutExtractor object. The PATH environment variable is not used when calling
       child processes: child process programs must be specified using paths.

       CoutExtractor objects may repeatedly be used to execute the same or different child processes.

       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 @).

Example

       #include <iostream>

       #include <bobcat/coutextractor>

       using namespace std;
       using namespace FBB;

       int main()
       {
           CoutExtractor extractor;

           extractor.execute("/bin/cat driver.cc");

           cout << extractor.rdbuf();

           cerr << "Returning: " << extractor.ret() << "\n"
                   "again:\n";

           extractor.execute("/bin/cat driver.cc");

           cout << extractor.rdbuf();

           cerr << "Returning: " << extractor.ret() << ’\n’;

       }

Files

bobcat/coutextractor - provides the class interface

Inherits From

FBB::Exec (private), FBB::IFdBuf (private), std::istream

Members

       o      voidexecute(std::stringconst&cmd):
              The argument specifies the command to execute: the command itself must be specified as a path (the
              PATH environment variable isn’t used).  This member immediately returns, after  which  information
              written by the child process to its standard output stream may be extracted from the CoutExtractor
              object.

              Once execute has returned it can be called again, either using the same or another command.

              Arguments  passed to the program to be executed as child process may optionally be specified using
              single or double quotes, as described in this man-page’s DESCRIPTION section.

       o      intret()const:
              Once execute has returned this member provides the actual exit code  of  the  child  process.  Its
              value equals -1 before the first exectue call.

Name

       FBB::CoutExtractor - Runs external programs writing standard output

Namespace

FBB
       All constructors, members, operators and manipulators, mentioned in this man-page,  are  defined  in  the
       namespace FBB.

Protected Member

       o      Pipe&childOutPipe():
              If  derived  classes  need to override the redirections-members then they probabaly need access to
              the pipe written by the child process. This member provides a reference to that pipe.  By  default
              the  parent  process reads information from the pipe, while the child process inserts its standard
              output into the pipe.

See Also

bobcat(7),  cerrextractor(3bobcat),   cininserter(3bobcat),   execl(3),   exec(3bobcat),   fork(3bobcat),
       process(3bobcat), stdextractor(3bobcat).

Synopsis

#include<bobcat/coutextractor>
       Linking option: -lbobcat

See Also