38 #ifndef BLOCXX_EXEC_HPP_INCLUDE_GUARD_
39 #define BLOCXX_EXEC_HPP_INCLUDE_GUARD_
41 #include "blocxx/BLOCXX_config.h"
45 #ifdef BLOCXX_ENABLE_TEST_HOOKS
49 namespace BLOCXX_NAMESPACE
87 template <
typename SA1,
typename SA2>
110 PreExec(
bool precompute_max_descriptors =
false);
122 virtual bool keepStd(
int d)
const = 0;
126 enum { MAX_MSG_LEN = 64 };
127 char message[MAX_MSG_LEN + 1];
158 virtual void call(pipe_pointer_t
const pparr[]) = 0;
166 void closeDescriptorsOnExec(std::vector<bool>
const & keep);
172 static void resetSignals();
180 static void closePipesOnExec(pipe_pointer_t
const pparr[]);
189 static void setupStandardDescriptors(pipe_pointer_t
const pparr[]);
197 static void setNewProcessGroup();
230 char const * exec_path,
231 char const *
const argv[],
char const *
const envp[],
246 template <
typename S,
typename SA1,
typename SA2>
248 S
const & exec_path, SA1
const & argv, SA2
const & envp,
255 return spawn(s_exec_path, sa_argv.
sarr, sa_envp.
sarr, pre_exec);
261 char const *
const argv[],
char const *
const envp[]
271 template <
typename SA1,
typename SA2>
273 SA1
const & argv, SA2
const & envp
281 template <
typename SA1>
357 : m_running(E_PROCESS_RUNNING)
362 explicit ProcessStatus(
int status)
363 : m_running(E_PROCESS_EXITED)
368 bool hasExited()
const
370 return m_running == E_PROCESS_EXITED;
373 const int& getStatus()
const
378 EProcessRunning m_running;
407 BLOCXX_COMMON_API
void processInputOutput(OutputCallback& output, Array<ProcessRef>& procs,
452 String
const & input = String());
495 int outputLimit = -1,
496 String
const & input = String());
529 char const *
const command[], String& output,
char const *
const envVars[],
531 char const * input = 0);
566 char const *
const command[], String& output, String& erroutput,
567 char const *
const envVars[],
569 char const * input = 0);
575 template <
typename SA1,
typename S1,
typename S2>
577 SA1
const & command, S1& output,
578 const Timeout& timeout,
int outputlimit, S2
const& input)
591 output = tmpOutput.
c_str();
594 output = tmpOutput.
c_str();
603 template <
typename SA1,
typename S1,
typename S2>
605 SA1
const & command, S1& output, S1& erroutput,
606 const Timeout& timeout,
int outputlimit, S2
const& input)
609 String tmpOutput, tmpErrOut;
619 output = tmpOutput.
c_str();
620 erroutput = tmpErrOut.
c_str();
623 output = tmpOutput.
c_str();
624 erroutput = tmpErrOut.
c_str();
632 template <
typename SA1,
typename S1>
634 SA1
const & command, S1& output,
647 output = tmpOutput.
c_str();
650 output = tmpOutput.
c_str();
659 template <
typename SA1,
typename S1>
661 SA1
const & command, S1& output, S1& erroutput,
665 String tmpOutput, tmpErrOut;
675 output = tmpOutput.
c_str();
676 erroutput = tmpErrOut.
c_str();
679 output = tmpOutput.
c_str();
680 erroutput = tmpErrOut.
c_str();
697 template <
typename SA1,
typename S1,
typename SA2,
typename S2>
699 SA1
const & command, S1& output, SA2
const & envp,
700 const Timeout& timeout,
int outputlimit, S2
const& input)
710 timeout, outputlimit, sInput);
714 output = tmpOutput.
c_str();
717 output = tmpOutput.
c_str();
735 template <
typename SA1,
typename S1,
typename SA2,
typename S2>
737 SA1
const & command, S1& output, S1& erroutput, SA2
const & envp,
738 const Timeout& timeout,
int outputlimit, S2
const& input)
742 String tmpOutput, tmpErrOut;
748 tmpErrOut, sa_envp.
sarr, timeout, outputlimit, sInput);
752 output = tmpOutput.
c_str();
753 erroutput = tmpErrOut.
c_str();
756 output = tmpOutput.
c_str();
757 erroutput = tmpErrOut.
c_str();
765 template <
typename SA1,
typename S1,
typename SA2>
767 SA1
const & command, S1& output, S1& erroutput, SA2
const & envp,
771 timeout, outputlimit,
String());
777 String& output,
int& processstatus,
778 int timeoutsecs = -1,
int outputlimit = -1,
800 #ifdef BLOCXX_ENABLE_TEST_HOOKS
static char const *const *const currentEnvironment
Intended to be used as a parameter to spawn() to indicate that the current environment will be used f...
unsigned const BLOCXX_OUT
#define BLOCXX_DECLARE_APIEXCEPTION2(NAME, BASE, LINKAGE_SPEC)
Declare a new exception class named <NAME>Exception that derives from <BASE>.
::BLOCXX_NAMESPACE::UnnamedPipe * pipe_pointer_t
Class for converting values of type S into char const * const *.
const UInt32 INFINITE_TIMEOUT BLOCXX_DEPRECATED
Value that means infinite timeout.
ProcessRef spawn(char const *exec_path, char const *const argv[], char const *const envp[], PreExec &pre_exec)
Run the executable exec_path in a child process, with argv for the program arguments and envp for the...
unsigned const BLOCXX_SERR
::BLOCXX_NAMESPACE::GlobalPtr< ExecMockObject, Impl::NullFactory > g_execMockObject
This String class is an abstract data type that represents as NULL terminated string of characters...
void gatherOutput(String &output, const ProcessRef &proc, int timeoutSecs, int outputLimit)
unsigned const BLOCXX_NPIPE
This class is used to specify what spawn() should do between fork and exec.
void processInputOutput(OutputCallback &output, Array< ProcessRef > &procs, InputCallback &input, const Timeout &timeout)
Send input and wait for output from child processes.
Process::Status system(const Array< String > &command, const char *const envp[], const Timeout &timeout)
Execute a command.
unsigned const BLOCXX_EXEC_ERR
A timeout can be absolute, which means that it will happen at the specified DateTime.
const char * c_str() const
int safeSystem(const Array< String > &command, const char *const envp[])
This is deprecated.
char const * to_char_ptr(S const &s)
Use this class to allow call() to throw an exception.
void close_child_ends(UnnamedPipeRef ppipe[BLOCXX_NPIPE])
#define BLOCXX_DECLARE_APIEXCEPTION(NAME, LINKAGE_SPEC)
Declare a new exception class named <NAME>Exception that derives from Exception This macro is typical...
IntrusiveReference< Process > ProcessRef
Process::Status executeProcessAndGatherOutput(char const *const command[], String &output, char const *const envVars[], const Timeout &timeout, int outputLimit, char const *input)
Execute a command and run feedProcessAndGatherOutput() on the process.
char const *const * sarr
Converted value.
This class can be used to store a global pointer.
Process::Status feedProcessAndGatherOutput(ProcessRef const &proc, String &output, Timeout const &timeout, int outputLimit, String const &input)
Send input to a process, collect the output, and wait for it to exit.