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
87 template <
typename SA1,
typename SA2>
98 const char*
const envp[] = 0) BLOCXX_DEPRECATED;
110 PreExec(
bool precompute_max_descriptors =
false);
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;
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
#define BLOCXX_DECLARE_APIEXCEPTION(NAME, LINKAGE_SPEC)
Declare a new exception class named <NAME>Exception that derives from Exception This macro is typical...
#define BLOCXX_DECLARE_APIEXCEPTION2(NAME, BASE, LINKAGE_SPEC)
Declare a new exception class named <NAME>Exception that derives from <BASE>.
Array<> wraps std::vector<> in COWReference<> adding ref counting and copy on write capability.
virtual void doHandleData(const char *data, size_t dataLen, EOutputSource outputSource, const ProcessRef &theProc, size_t streamIndex, Array< char > &inputBuffer)=0
void handleData(const char *data, size_t dataLen, EOutputSource outputSource, const ProcessRef &theProc, size_t streamIndex, Array< char > &inputBuffer)
This class is used to specify what spawn() should do between fork and exec.
::BLOCXX_NAMESPACE::UnnamedPipe * pipe_pointer_t
static void setupStandardDescriptors(pipe_pointer_t const pparr[])
For calling from PreExec::call.
static void resetSignals()
For calling from PreExec::call.
void closeDescriptorsOnExec(std::vector< bool > const &keep)
For calling from PreExec::call.
virtual void call(pipe_pointer_t const pparr[])=0
This function is called between fork and exec in the spawn() function.
PreExec(bool precompute_max_descriptors=false)
static void setNewProcessGroup()
For calling from PreExec::call().
static void closePipesOnExec(pipe_pointer_t const pparr[])
For calling from PreExec::call.
virtual bool keepStd(int d) const =0
ExecErrorException(const char *file, int line, const char *msg, int errorCode=::BLOCXX_NAMESPACE::Exception::UNKNOWN_ERROR_CODE, const Exception *otherException=0, int subClassId=::BLOCXX_NAMESPACE::Exception::UNKNOWN_SUBCLASS_ID)
This class can be used to store a global pointer.
This String class is an abstract data type that represents as NULL terminated string of characters.
const char * c_str() const
A timeout can be absolute, which means that it will happen at the specified DateTime.
Abstract interface for an UnnamedPipe.
char const * to_char_ptr(S const &s)
unsigned const BLOCXX_OUT
unsigned const BLOCXX_NPIPE
void close_child_ends(UnnamedPipeRef ppipe[BLOCXX_NPIPE])
unsigned const BLOCXX_EXEC_ERR
unsigned const BLOCXX_SERR
int safeSystem(const Array< String > &command, const char *const envp[])
This is deprecated.
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.
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...
void processInputOutput(OutputCallback &output, Array< ProcessRef > &procs, InputCallback &input, const Timeout &timeout)
Send input and wait for output from child processes.
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.
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...
::BLOCXX_NAMESPACE::GlobalPtr< ExecMockObject, Impl::NullFactory > g_execMockObject
Process::Status system(const Array< String > &command, const char *const envp[], const Timeout &timeout)
Execute a command.
void gatherOutput(String &output, const ProcessRef &proc, int timeoutSecs, int outputLimit)
IntrusiveReference< UnnamedPipe > UnnamedPipeRef
IntrusiveReference< Process > ProcessRef
Class for converting values of type S into char const * const *.
char const *const * sarr
Converted value.
Use this class to allow call() to throw an exception.
char message[MAX_MSG_LEN+1]