\r
// Author: Andy Rushton\r
// Copyright: (c) Southampton University 1999-2004\r
-// (c) Andy Rushton 2004-2009\r
+// (c) Andy Rushton 2004 onwards\r
// License: BSD License, see ../docs/license.html\r
- \r
+\r
// Platform-independent wrapper around the very platform-specific handling of\r
// subprocesses. Uses the C++ convention that all resources must be contained in\r
// an object so that when a subprocess object goes out of scope the subprocess\r
#else\r
#define ENVIRON_TYPE char**\r
#endif\r
+ class subprocess;\r
+ class async_subprocess;\r
\r
class env_vector\r
{\r
private:\r
ENVIRON_TYPE m_env;\r
+ friend class subprocess;\r
+ friend class async_subprocess;\r
+ // access the env_vector as an envp type - used for passing to subprocesses\r
+ ENVIRON_TYPE envp (void) const;\r
\r
public:\r
// create an env_vector vector from the current process\r
\r
env_vector& operator = (const env_vector&);\r
\r
- void clear (void);\r
-\r
// manipulate the env_vector by adding or removing variables\r
// adding a name that already exists replaces its value\r
void add (const std::string& name, const std::string& value);\r
bool remove (const std::string& name);\r
+ void clear (void);\r
\r
// get the value associated with a name\r
// the first uses an indexed notation (e.g. env["PATH"] )\r
// the second is a function based form (e.g. env.get("PATH"))\r
+ bool present(const std::string& name) const;\r
std::string operator [] (const std::string& name) const;\r
std::string get (const std::string& name) const;\r
\r
// get the name=value pairs by index (in the range 0 to size()-1)\r
std::pair<std::string,std::string> operator [] (unsigned index) const throw(std::out_of_range);\r
std::pair<std::string,std::string> get (unsigned index) const throw(std::out_of_range);\r
-\r
- // access the env_vector as an envp type - used for passing to subprocesses\r
- ENVIRON_TYPE envp (void) const;\r
};\r
\r
////////////////////////////////////////////////////////////////////////////////\r
\r
class subprocess\r
{\r
- private:\r
+ protected:\r
\r
PID_TYPE m_pid;\r
#ifdef MSWINDOWS\r
env_vector m_env;\r
int m_err;\r
int m_status;\r
+ void set_error(int);\r
\r
public:\r
subprocess(void);\r
\r
void add_variable(const std::string& name, const std::string& value);\r
bool remove_variable(const std::string& name);\r
+ const env_vector& get_variables(void) const;\r
\r
bool spawn(const std::string& path, const arg_vector& argv,\r
bool connect_stdin = false, bool connect_stdout = false, bool connect_stderr = false);\r
\r
class backtick_subprocess : public subprocess\r
{\r
- private:\r
+ protected:\r
std::string m_text;\r
public:\r
backtick_subprocess(void);\r
\r
class async_subprocess\r
{\r
- private:\r
+ protected:\r
PID_TYPE m_pid;\r
#ifdef MSWINDOWS\r
HANDLE m_job;\r
\r
void add_variable(const std::string& name, const std::string& value);\r
bool remove_variable(const std::string& name);\r
+ const env_vector& get_variables(void) const;\r
\r
bool spawn(const std::string& path, const arg_vector& argv,\r
bool connect_stdin = false, bool connect_stdout = false, bool connect_stderr = false);\r