Boost C++ Libraries


Class command_line

boost::process::command_line — Implementation of the Command_Line concept.


class command_line {
// types
typedef std::vector< std::string > arguments_vector;  // Type used to represent the argument's vector. 

// construct/copy/destruct
command_line(const std::string &, const std::string & = "", 
const std::string & = "");

// public member functions
template<typename T> command_line & argument(const T &) ;
const arguments_vector & get_arguments(void) const;
const std::string & get_executable(void) const;

// public static functions
static command_line shell(const std::string &) ;


A command_line object represents the command line used to launch a process. It includes the path to the executable file as well as all the arguments passed to it. This class also includes some convenience functions to ease the launcher's task.

It is important to note that the list of arguments passed to the binary must always include at least an element that indicates the program's name. Its value generally matches the binary's base name, but can be changed by the user. The class enforces this requirement.

command_line construct/copy/destruct

  1. command_line(const std::string & executable, 
    const std::string & firstarg = "", 
    const std::string & path = "");

    Constructs a new command line given an executable and its program name. If the executable name does not have any directory component, it is automatically searched in the path given by path or, if empty, in the directories listed by the PATH environment variable.


    The full path to the executable program.


    The program's name. If empty, the constructor sets it to be the executable's base name (i.e., skips the directory).


    Set of directories where to look for the executable, if it does not include any path component.

    Throws: not_found_error&lt;std::string&gt;

command_line public member functions

  1. template<typename T> command_line & argument(const T & argument) ;

    This templated method appends a new argument to the command line. The argument's type has to be allowed on the RHS of a << operator.

    In a POSIX system, arguments given using this function are passed to the binary as exactly one argument. They are not subject to quoting problems. In a Win32 system, this is unavoidable given that the process' command line is provided in a single string where quoting issues may arise.


    A reference to the modified command line to allow daisy-chaining calls to argument().

  2. const arguments_vector & get_arguments(void ) const;

    Returns the arguments list.

  3. const std::string & get_executable(void ) const;

    Returns the executable's path.

command_line public static functions

  1. static command_line shell(const std::string & command) ;

    Constructs a command line that is fed to the system's shell for further processing. This command line is subject to pattern expansion, redirection and pipelining.

    In a POSIX system, the command line is fed to /bin/sh; under a Win32 system, it is fed to cmd.exe. This makes it difficult to write really portable command lines using this pseudo-constructor.

Copyright 2006 Julio M. Merino Vidal