Boost C++ Libraries Home Libraries People FAQ More

Next

Chapter 1. Boost.Process

Boris Schaeling

Felipe Tanus

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Introduction
User Guide
Header files
Creating child processes
Configuring runtime contexts
Communicating with child processes
Asynchronous I/O
Waiting for a process to exit
Terminating a process
Creating new stream behaviors
POSIX extensions
Windows extensions
Reference
Header <boost/process.hpp>
Header <boost/process/process.hpp>
Header <boost/process/all.hpp>
Header <boost/process/child.hpp>
Header <boost/process/config.hpp>
Header <boost/process/context.hpp>
Header <boost/process/environment.hpp>
Header <boost/process/handle.hpp>
Header <boost/process/operations.hpp>
Header <boost/process/pid_type.hpp>
Header <boost/process/pipe.hpp>
Header <boost/process/pistream.hpp>
Header <boost/process/postream.hpp>
Header <boost/process/self.hpp>
Header <boost/process/status.hpp>
Header <boost/process/stream_behavior.hpp>
Header <boost/process/stream_ends.hpp>
Header <boost/process/stream_id.hpp>
Header <boost/process/stream_type.hpp>
Appendices
Future improvements

Boost.Process is a library to manage system processes. It can be used to:

  • create child processes
  • run shell commands
  • setup environment variables for child processes
  • setup standard streams for child processes (and other streams on POSIX platforms)
  • communicate with child processes through standard streams (synchronously or asynchronously)
  • wait for processes to exit (synchronously or asynchronously)
  • terminate processes

While Boost.Process does not support platform specific features it provides extension points. Developers can plug in functions, eg. to set the uid of a child process on a POSIX system.

Here's an example of how easy it is to start a program with Boost.Process.

#include <boost/process/all.hpp> 
#include <string> 

int main() 
{ 
    std::string exe = boost::process::find_executable_in_path("hostname"); 
    boost::process::create_child(exe); 
} 

The example searches for an executable hostname in the directories of the environment variable PATH and starts the program. As the standard output stream is inherited the hostname is printed when you run the example.

Last revised: October 06, 2010 at 22:00:35 GMT


Next