38#include "blocxx/BLOCXX_config.h"
47#if !defined(BLOCXX_WIN32)
57#ifdef BLOCXX_HAVE_SYS_RESOURCE_H
58#include <sys/resource.h>
60#ifdef BLOCXX_HAVE_SYS_TYPES_H
63#ifdef BLOCXX_HAVE_UNISTD_H
77#define SIG_DFL (void(*)())0
106 return proc->processStatus();
115 return ps.getPOSIXwaitpidStatus();
121 char const *
const argv[],
char const *
const envp[],
135 char const *
const argv[],
char const *
const envp[],
148 char const *
const argv[],
char const *
const envp[]
186#define BLOCXX_MIN(x, y) (x) < (y) ? (x) : (y)
190class StringOutputGatherer :
public OutputCallback
206 virtual void doHandleData(
const char* data,
size_t dataLen,
220 "Exec::StringOutputGatherer::doHandleData(): buffer full");
231class SingleStringInputCallback :
public InputCallback
234 SingleStringInputCallback(
const String& s)
241 if (
m_s.length() > 0)
246 else if (
theProc->in()->isOpen())
326 proc->waitCloseTerm();
327 return proc->processStatus();
344 proc->waitCloseTerm();
345 return proc->processStatus();
392 struct ProcessOutputState
424 if (!
procs[
i]->out()->isOpen())
428 if (!
procs[
i]->err()->isOpen())
432 if (!
procs[
i]->in()->isOpen())
446 for (
size_t i = 0;
i <
procs.size(); ++
i)
451 selObj.waitForRead =
true;
458 selObj.waitForRead =
true;
465 selObj.waitForWrite =
true;
#define BLOCXX_DEFINE_EXCEPTION_WITH_ID(NAME)
Define a new exception class named <NAME>Exception that derives from Exception.
#define BLOCXX_THROW(exType, msg)
Throw an exception using FILE and LINE.
#define BLOCXX_DEFINE_EXCEPTION_WITH_BASE_AND_ID(NAME, BASE)
Define a new exception class named <NAME>Exception that derives from <BASE>.
#define BLOCXX_THROW_ERRNO_MSG(exType, msg)
Throw an exception using FILE, LINE, errno and strerror(errno)
#define BLOCXX_GLOBAL_PTR_INIT
This macro is provided to abstract the details of GlobalPtr.
Array<> wraps std::vector<> in COWReference<> adding ref counting and copy on write capability.
void push_back(const T &x)
Append an element to the end of the Array.
virtual void doHandleData(const char *data, size_t dataLen, EOutputSource outputSource, const ProcessRef &theProc, size_t streamIndex, Array< char > &inputBuffer)=0
virtual ~OutputCallback()
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.
This class can be used to store a global pointer.
virtual int write(const void *dataOut, int dataOutLen, ErrorAction errorAsException=E_RETURN_ON_ERROR)=0
Write a specified number of bytes to the device that is exposing the IOIFC interface.
virtual int read(void *dataIn, int dataInLen, ErrorAction errorAsException=E_RETURN_ON_ERROR)=0
Read a specified number of bytes from the device that is exposing the IOIFC interface.
This String class is an abstract data type that represents as NULL terminated string of characters.
A timeout can be absolute, which means that it will happen at the specified DateTime.
static Timeout relativeWithReset(float seconds)
static Timeout relative(float seconds)
A TimeoutTimer is used by an algorithm to determine when a timeout has expired.
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.
ProcessRef spawnImpl(char const *exec_path, char const *const argv[], char const *const envp[], PreExec &pre_exec)
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.
::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)
ProcessRef spawnImpl(char const *exec_path, char const *const argv[], char const *const envp[], Exec::PreExec &pre_exec)
const int SELECT_TIMEOUT
The value returned from select when the timeout value has expired.
int selectRW(SelectObjectArray &selarray, UInt32 ms)
const int SELECT_ERROR
The value returned from select when any error occurs other than timeout.
BLOCXX_COMMON_API ProcessRef spawnProcess(char const *exec_path, char const *const argv[], char const *const envp[], Exec::PreExec &pre_exec)
BLOCXX_COMMON_API bool shouldUseWaitpidThreadFix()
ProcessRef spawnImpl(char const *exec_path, char const *const argv[], char const *const envp[], Exec::PreExec &pre_exec)
IntrusiveReference< Process > ProcessRef
bool operator==(const Array< T > &x, const Array< T > &y)