diff options
Diffstat (limited to 'lib/Support/Program.cpp')
-rw-r--r-- | lib/Support/Program.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/Support/Program.cpp b/lib/Support/Program.cpp index 79f7e5f..83f2ec4 100644 --- a/lib/Support/Program.cpp +++ b/lib/Support/Program.cpp @@ -22,30 +22,40 @@ using namespace sys; //=== independent code. //===----------------------------------------------------------------------===// -static bool Execute(void **Data, StringRef Program, const char **args, +static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, const char **env, const StringRef **Redirects, unsigned memoryLimit, std::string *ErrMsg); -static int Wait(void *&Data, StringRef Program, unsigned secondsToWait, - std::string *ErrMsg); - int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp, const StringRef **redirects, unsigned secondsToWait, unsigned memoryLimit, std::string *ErrMsg, bool *ExecutionFailed) { - void *Data = 0; - if (Execute(&Data, Program, args, envp, redirects, memoryLimit, ErrMsg)) { - if (ExecutionFailed) *ExecutionFailed = false; - return Wait(Data, Program, secondsToWait, ErrMsg); + ProcessInfo PI; + if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) { + if (ExecutionFailed) + *ExecutionFailed = false; + ProcessInfo Result = Wait(PI, secondsToWait, true, ErrMsg); + return Result.ReturnCode; } - if (ExecutionFailed) *ExecutionFailed = true; + + if (ExecutionFailed) + *ExecutionFailed = true; + return -1; } -void sys::ExecuteNoWait(StringRef Program, const char **args, const char **envp, - const StringRef **redirects, unsigned memoryLimit, - std::string *ErrMsg) { - Execute(/*Data*/ 0, Program, args, envp, redirects, memoryLimit, ErrMsg); +ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args, + const char **envp, const StringRef **redirects, + unsigned memoryLimit, std::string *ErrMsg, + bool *ExecutionFailed) { + ProcessInfo PI; + if (ExecutionFailed) + *ExecutionFailed = false; + if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) + if (ExecutionFailed) + *ExecutionFailed = true; + + return PI; } // Include the platform-specific parts of this class. |