includefile(include/header)

COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::CinInserter)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_)
                    (Executing Child Processes)

manpagename(FBB::CinInserter)(Runs external programs reading standard input)

manpagesynopsis()
    bf(#include <bobcat/cininserter>)nl()
    Linking option: tt(-lbobcat)

manpagedescription()
    The bf(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 tt(CinInserter) objects. The child's standard
input is provided through the tt(CinInserter) object: information inserted
into an tt(CinInserter) object is forwarded to the child process's standard
input stream. The tt(PATH) environment variable is not used when calling child
processes: child process programs must be specified using paths.

tt(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., tt(\100) is converted to tt(@)).

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 tt(InterterFork) offers an
overloaded tt(execute) member, passing information to the child process via a
separate thread.

includefile(include/namespace)

manpagesection(INHERITS FROM)
    bf(FBB::Exec) (private),
    bf(FBB::OFdBuf) (private),
    bf(std::ostream).

manpagesection(CONSTRUCTOR)

    itemization(
    itb(CinInserter(size_t bufSize = 100))
       A tt(bufSize) argument may be specified: it defines the internal buffer
        size used by the tt(CinInserter's) streambuf. By default the stdandard
        output and standard error streams are not handled.
    itb(CinInserter(Mode mode, size_t bufSize = 100))
       The tt(mode) argument must be tt(CinInserter::CLOSE_STD). It indicates
        that the standard output and standard error streams are redirected to
        tt(/dev/null): any standard output generated by child processes is
        ignored. A tt(bufSize) argument may be specified: it defines the
        internal buffer size used by the tt(CinInserter's) streambuf.
    )

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

manpagesection(DESTRUCTOR)

    The destructor ends the tt(CinInserter's) child process, if it is still
    active.

manpagesection(MEMBERS)

    itemization(
    itb(void execute(std::string const &cmd))
        The argument specifies the command to execute: the command itself must
be specified as a path (the tt(PATH) environment variable isn't used).  This
member immediately returns, after which information can be inserted into the
tt(CinInserter) object which is then forwarded to the childprocess's standard
input stream. See also the description of the next (overloaded tt(execute))
member function.

Once all information has been inserted, the child process's standard input
stream must be closed. This is realized by either calling tt(stop); by
calling tt(execute) once again; or by ending the tt(CinInserter) object's
lifetime.

Arguments specified in the tt(cmd) string are passed to the child process, and
may optionally be specified using single or double quotes, as described in
this man-page's DESCRIPTION section.

    itb(bool execute(std::string const &cmd, std::string const &text))
        This member is used to forward a limited amount of information
(contained in the tt(text) parameter) to the child process specified at
tt(cmd) (defined identically as the tt(cmd) parameter of the previous
tt(execute) member).

This member returns tt(true) if the child process's exit value equals 0.

    itb(int stop())
        This function can be called after all information has been inserted
into the tt(CinInserter) object to close the child process's standard input
stream. It is not required after calling tt(execute(cmd, text)), or when
calling tt(execute) again, or when the tt(CinInseror) object's lifetime ends.

    This member returns the exit code of the last executed child process,
which may also be obtained from the next member:

    itb(int ret() const)
        Once a child process has finished this member provides the actual exit
code of the child process. Its value equals -1 before the first tt(exectue)
call.
    )

manpagesection(PROTECTED MEMBER)

    itemization(
    itb(Pipe &childInPipe())
       If derived classes need to override the redirections-members then they
        probabaly need access to the pipe read by the child process. This
        member provides a reference to that pipe. By default the parent
        process inserts information into the pipe, while the
        child process reads the inserted information from the pipe.
    )

manpagesection(EXAMPLE)

    verbinclude(../../cininserter/driver/driver.cc)

manpagefiles()
    em(bobcat/cininserter) - provides the class interface

manpageseealso()
    bf(bobcat)(7), bf(cerrextractor)(3bobcat), bf(coutextractor)(3bobcat),
    bf(execl)(3), bf(exec)(3bobcat),
    bf(fork)(3bobcat), bf(pipe)(3bobcat), bf(process)(3bobcat),
    bf(stdextractor)(3bobcat).

manpagebugs()
    None reported.

includefile(include/trailer)
