Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2008-08-31 12:23:30


Hi to all,

I recently needed s library to launch processes and I took a look to the
recently announced Process 0.2
(http://lists.boost.org/Archives/boost/2008/07/139322.php).

I just needed the library for Windows, and I think the library is
interesting although still lacking in some basic aspects (explained
later in this post).

A process-launching library is a very nice utility for Interprocess and
I was thinking of adding this possibility for a future version (Boost
1.37 or 1.38) of the library. If Boost.Process is going forward, it
would be glad to collaborate and develop a library that can satisfy all
our needs and plays nicely with Interprocess.

My main requests for a process-launching library are:

1) Ability to launch a process and a blocking or non-blocking wait
operation to obtain its result (Boost.Process already has this).

2) Ability to redirect child process stdin/stdout/stderr to /dev/null,
to share the stdin/stdout of the parent or to redirect it to a file. And
in the latter case, append or overwrite options (Boost.Process
implements some of this options). I slightly modified Boost.Process to
implement a rought version of file redirection.

3) Ability to modify the environment variables of the child
(Boost.Process already has this).

4) Blocking and non-blocking redirections of stdout and helper functions
to simplify its usage (Boost.Process does not have this). For example:

bool send_stdio_and_get_stdout (const void* stdin, std::size_t
stdin_size, std::vector<char> &stdout);

or similar would avoid many programming errors because at any moment
stdin can block and we must extract stdout so that the child process can
continue processing stdin.

5) I don't know if streams are the right way to communicate with
processes, because they don't offer non-blocking support.

6) I think that process-launching interface should be similar to the
soon to be standardized C++ futures.

So I'm interested in a process-launching library and I offer my
collaboration in case Boost.Process development needs help.

Regards,

Ion

PS: Some possible bugs found on Boost.Process 0.2 version (Windows):

-> main thread handle returned by CreateProcess in PROCESS_INFORMATION
structure the must be closed and I can't find this in the code.

-> child::wait function returns sporadic errors when multiple children
are launched and waited. I changed the code from:
      do
      {
           ::GetExitCodeProcess(handle_, &code);
           ::Sleep(500);
       } while (code == STILL_ACTIVE);
       ::WaitForSingleObject(handle_, 0);
       ::CloseHandle(handle_);

with

       ::WaitForSingleObject(handle_, INFINITE);
       ::GetExitCodeProcess(handle_, &code);
       ::CloseHandle(handle_);

->environment::set does not correctly overwrite existing variables):

void set(const std::string &var, const std::string &value)
{
    insert(value_type(var, value);
}

should be

void set(const std::string &var, const std::string &value)
{
    this->operator[](var) = value;
}

-> Using named pipes has been problematic because it returns errors when
launching multiple processes aggressively: Error 231 - All Pipes are
Busy. This does not happen with anonymous pipes and I think it has some
relationship with the guid code. By the way, I think a uuid library is
too much to create a unique identifier to be shared with the child a
simple atomic count would to the job in my opinion. That would reduce
Boost.Process dependencies.

-> systembuf::close() should call sync() to push the last charaters into
the pipe, othewise, characters are lost if the user does not flush the
stream.

-> I've changed the "stream_info::usefile" case in win32_start to
support redirecting to files, changing "CREATE_NEW" parameter of
CreateFileA with CREATE_ALWAYS.

-> And now, the most important one ;-)

Please, avoid tabs! Read boost development guidelines:

http://www.boost.org/development/requirements.html#Tabs


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk