diff options
Diffstat (limited to 'Source/kwsys/Process.h.in')
-rw-r--r-- | Source/kwsys/Process.h.in | 356 |
1 files changed, 230 insertions, 126 deletions
diff --git a/Source/kwsys/Process.h.in b/Source/kwsys/Process.h.in index c5995eac1..237001c60 100644 --- a/Source/kwsys/Process.h.in +++ b/Source/kwsys/Process.h.in @@ -1,14 +1,5 @@ -/*============================================================================ - KWSys - Kitware System Library - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ #ifndef @KWSYS_NAMESPACE@_Process_h #define @KWSYS_NAMESPACE@_Process_h @@ -19,66 +10,78 @@ not visible to user code. Use kwsysHeaderDump.pl to reproduce these macros after making changes to the interface. */ #if !defined(KWSYS_NAMESPACE) -# define kwsys_ns(x) @KWSYS_NAMESPACE@##x -# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT +#define kwsys_ns(x) @KWSYS_NAMESPACE@##x +#define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT #endif #if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS -# define kwsysProcess kwsys_ns(Process) -# define kwsysProcess_s kwsys_ns(Process_s) -# define kwsysProcess_New kwsys_ns(Process_New) -# define kwsysProcess_Delete kwsys_ns(Process_Delete) -# define kwsysProcess_SetCommand kwsys_ns(Process_SetCommand) -# define kwsysProcess_AddCommand kwsys_ns(Process_AddCommand) -# define kwsysProcess_SetTimeout kwsys_ns(Process_SetTimeout) -# define kwsysProcess_SetWorkingDirectory kwsys_ns(Process_SetWorkingDirectory) -# define kwsysProcess_SetPipeFile kwsys_ns(Process_SetPipeFile) -# define kwsysProcess_SetPipeNative kwsys_ns(Process_SetPipeNative) -# define kwsysProcess_SetPipeShared kwsys_ns(Process_SetPipeShared) -# define kwsysProcess_Option_Detach kwsys_ns(Process_Option_Detach) -# define kwsysProcess_Option_HideWindow kwsys_ns(Process_Option_HideWindow) -# define kwsysProcess_Option_Verbatim kwsys_ns(Process_Option_Verbatim) -# define kwsysProcess_GetOption kwsys_ns(Process_GetOption) -# define kwsysProcess_SetOption kwsys_ns(Process_SetOption) -# define kwsysProcess_Option_e kwsys_ns(Process_Option_e) -# define kwsysProcess_State_Starting kwsys_ns(Process_State_Starting) -# define kwsysProcess_State_Error kwsys_ns(Process_State_Error) -# define kwsysProcess_State_Exception kwsys_ns(Process_State_Exception) -# define kwsysProcess_State_Executing kwsys_ns(Process_State_Executing) -# define kwsysProcess_State_Exited kwsys_ns(Process_State_Exited) -# define kwsysProcess_State_Expired kwsys_ns(Process_State_Expired) -# define kwsysProcess_State_Killed kwsys_ns(Process_State_Killed) -# define kwsysProcess_State_Disowned kwsys_ns(Process_State_Disowned) -# define kwsysProcess_GetState kwsys_ns(Process_GetState) -# define kwsysProcess_State_e kwsys_ns(Process_State_e) -# define kwsysProcess_Exception_None kwsys_ns(Process_Exception_None) -# define kwsysProcess_Exception_Fault kwsys_ns(Process_Exception_Fault) -# define kwsysProcess_Exception_Illegal kwsys_ns(Process_Exception_Illegal) -# define kwsysProcess_Exception_Interrupt kwsys_ns(Process_Exception_Interrupt) -# define kwsysProcess_Exception_Numerical kwsys_ns(Process_Exception_Numerical) -# define kwsysProcess_Exception_Other kwsys_ns(Process_Exception_Other) -# define kwsysProcess_GetExitException kwsys_ns(Process_GetExitException) -# define kwsysProcess_Exception_e kwsys_ns(Process_Exception_e) -# define kwsysProcess_GetExitCode kwsys_ns(Process_GetExitCode) -# define kwsysProcess_GetExitValue kwsys_ns(Process_GetExitValue) -# define kwsysProcess_GetErrorString kwsys_ns(Process_GetErrorString) -# define kwsysProcess_GetExceptionString kwsys_ns(Process_GetExceptionString) -# define kwsysProcess_Execute kwsys_ns(Process_Execute) -# define kwsysProcess_Disown kwsys_ns(Process_Disown) -# define kwsysProcess_WaitForData kwsys_ns(Process_WaitForData) -# define kwsysProcess_Pipes_e kwsys_ns(Process_Pipes_e) -# define kwsysProcess_Pipe_None kwsys_ns(Process_Pipe_None) -# define kwsysProcess_Pipe_STDIN kwsys_ns(Process_Pipe_STDIN) -# define kwsysProcess_Pipe_STDOUT kwsys_ns(Process_Pipe_STDOUT) -# define kwsysProcess_Pipe_STDERR kwsys_ns(Process_Pipe_STDERR) -# define kwsysProcess_Pipe_Timeout kwsys_ns(Process_Pipe_Timeout) -# define kwsysProcess_Pipe_Handle kwsys_ns(Process_Pipe_Handle) -# define kwsysProcess_WaitForExit kwsys_ns(Process_WaitForExit) -# define kwsysProcess_Kill kwsys_ns(Process_Kill) +#define kwsysProcess kwsys_ns(Process) +#define kwsysProcess_s kwsys_ns(Process_s) +#define kwsysProcess_New kwsys_ns(Process_New) +#define kwsysProcess_Delete kwsys_ns(Process_Delete) +#define kwsysProcess_SetCommand kwsys_ns(Process_SetCommand) +#define kwsysProcess_AddCommand kwsys_ns(Process_AddCommand) +#define kwsysProcess_SetTimeout kwsys_ns(Process_SetTimeout) +#define kwsysProcess_SetWorkingDirectory kwsys_ns(Process_SetWorkingDirectory) +#define kwsysProcess_SetPipeFile kwsys_ns(Process_SetPipeFile) +#define kwsysProcess_SetPipeNative kwsys_ns(Process_SetPipeNative) +#define kwsysProcess_SetPipeShared kwsys_ns(Process_SetPipeShared) +#define kwsysProcess_Option_Detach kwsys_ns(Process_Option_Detach) +#define kwsysProcess_Option_HideWindow kwsys_ns(Process_Option_HideWindow) +#define kwsysProcess_Option_MergeOutput kwsys_ns(Process_Option_MergeOutput) +#define kwsysProcess_Option_Verbatim kwsys_ns(Process_Option_Verbatim) +#define kwsysProcess_Option_CreateProcessGroup \ + kwsys_ns(Process_Option_CreateProcessGroup) +#define kwsysProcess_GetOption kwsys_ns(Process_GetOption) +#define kwsysProcess_SetOption kwsys_ns(Process_SetOption) +#define kwsysProcess_Option_e kwsys_ns(Process_Option_e) +#define kwsysProcess_State_Starting kwsys_ns(Process_State_Starting) +#define kwsysProcess_State_Error kwsys_ns(Process_State_Error) +#define kwsysProcess_State_Exception kwsys_ns(Process_State_Exception) +#define kwsysProcess_State_Executing kwsys_ns(Process_State_Executing) +#define kwsysProcess_State_Exited kwsys_ns(Process_State_Exited) +#define kwsysProcess_State_Expired kwsys_ns(Process_State_Expired) +#define kwsysProcess_State_Killed kwsys_ns(Process_State_Killed) +#define kwsysProcess_State_Disowned kwsys_ns(Process_State_Disowned) +#define kwsysProcess_State_e kwsys_ns(Process_State_e) +#define kwsysProcess_Exception_None kwsys_ns(Process_Exception_None) +#define kwsysProcess_Exception_Fault kwsys_ns(Process_Exception_Fault) +#define kwsysProcess_Exception_Illegal kwsys_ns(Process_Exception_Illegal) +#define kwsysProcess_Exception_Interrupt kwsys_ns(Process_Exception_Interrupt) +#define kwsysProcess_Exception_Numerical kwsys_ns(Process_Exception_Numerical) +#define kwsysProcess_Exception_Other kwsys_ns(Process_Exception_Other) +#define kwsysProcess_Exception_e kwsys_ns(Process_Exception_e) +#define kwsysProcess_GetState kwsys_ns(Process_GetState) +#define kwsysProcess_GetExitException kwsys_ns(Process_GetExitException) +#define kwsysProcess_GetExitCode kwsys_ns(Process_GetExitCode) +#define kwsysProcess_GetExitValue kwsys_ns(Process_GetExitValue) +#define kwsysProcess_GetErrorString kwsys_ns(Process_GetErrorString) +#define kwsysProcess_GetExceptionString kwsys_ns(Process_GetExceptionString) +#define kwsysProcess_GetStateByIndex kwsys_ns(Process_GetStateByIndex) +#define kwsysProcess_GetExitExceptionByIndex \ + kwsys_ns(Process_GetExitExceptionByIndex) +#define kwsysProcess_GetExitCodeByIndex kwsys_ns(Process_GetExitCodeByIndex) +#define kwsysProcess_GetExitValueByIndex kwsys_ns(Process_GetExitValueByIndex) +#define kwsysProcess_GetExceptionStringByIndex \ + kwsys_ns(Process_GetExceptionStringByIndex) +#define kwsysProcess_GetExitCodeByIndex kwsys_ns(Process_GetExitCodeByIndex) +#define kwsysProcess_Execute kwsys_ns(Process_Execute) +#define kwsysProcess_Disown kwsys_ns(Process_Disown) +#define kwsysProcess_WaitForData kwsys_ns(Process_WaitForData) +#define kwsysProcess_Pipes_e kwsys_ns(Process_Pipes_e) +#define kwsysProcess_Pipe_None kwsys_ns(Process_Pipe_None) +#define kwsysProcess_Pipe_STDIN kwsys_ns(Process_Pipe_STDIN) +#define kwsysProcess_Pipe_STDOUT kwsys_ns(Process_Pipe_STDOUT) +#define kwsysProcess_Pipe_STDERR kwsys_ns(Process_Pipe_STDERR) +#define kwsysProcess_Pipe_Timeout kwsys_ns(Process_Pipe_Timeout) +#define kwsysProcess_Pipe_Handle kwsys_ns(Process_Pipe_Handle) +#define kwsysProcess_WaitForExit kwsys_ns(Process_WaitForExit) +#define kwsysProcess_Interrupt kwsys_ns(Process_Interrupt) +#define kwsysProcess_Kill kwsys_ns(Process_Kill) +#define kwsysProcess_ResetStartTime kwsys_ns(Process_ResetStartTime) #endif #if defined(__cplusplus) -extern "C" -{ +extern "C" { #endif /** @@ -186,12 +189,27 @@ kwsysEXPORT void kwsysProcess_SetPipeNative(kwsysProcess* cp, int pipe, * 0 = No (default) * 1 = Yes * + * kwsysProcess_Option_MergeOutput = Whether to merge stdout/stderr. + * No content will be returned as stderr. + * Any actual stderr will be on stdout. + * 0 = No (default) + * 1 = Yes + * * kwsysProcess_Option_Verbatim = Whether SetCommand and AddCommand * should treat the first argument * as a verbatim command line * and ignore the rest of the arguments. * 0 = No (default) * 1 = Yes + * + * kwsysProcess_Option_CreateProcessGroup = Whether to place the process in a + * new process group. This is + * useful if you want to send Ctrl+C + * to the process. On UNIX, also + * places the process in a new + * session. + * 0 = No (default) + * 1 = Yes */ kwsysEXPORT int kwsysProcess_GetOption(kwsysProcess* cp, int optionId); kwsysEXPORT void kwsysProcess_SetOption(kwsysProcess* cp, int optionId, @@ -200,7 +218,9 @@ enum kwsysProcess_Option_e { kwsysProcess_Option_HideWindow, kwsysProcess_Option_Detach, - kwsysProcess_Option_Verbatim + kwsysProcess_Option_MergeOutput, + kwsysProcess_Option_Verbatim, + kwsysProcess_Option_CreateProcessGroup }; /** @@ -235,9 +255,12 @@ enum kwsysProcess_State_e * * kwsysProcess_Exception_None = No exceptional behavior occurred. * kwsysProcess_Exception_Fault = Child crashed with a memory fault. - * kwsysProcess_Exception_Illegal = Child crashed with an illegal instruction. - * kwsysProcess_Exception_Interrupt = Child was interrupted by user (Cntl-C/Break). - * kwsysProcess_Exception_Numerical = Child crashed with a numerical exception. + * kwsysProcess_Exception_Illegal = Child crashed with an illegal + * instruction. + * kwsysProcess_Exception_Interrupt = Child was interrupted by user + * (Cntl-C/Break). + * kwsysProcess_Exception_Numerical = Child crashed with a numerical + * exception. * kwsysProcess_Exception_Other = Child terminated for another reason. */ kwsysEXPORT int kwsysProcess_GetExitException(kwsysProcess* cp); @@ -283,6 +306,67 @@ kwsysEXPORT const char* kwsysProcess_GetErrorString(kwsysProcess* cp); kwsysEXPORT const char* kwsysProcess_GetExceptionString(kwsysProcess* cp); /** +* Get the current state of the Process instance. Possible states are: +* +* kwsysProcess_StateByIndex_Starting = Execute has not yet been called. +* kwsysProcess_StateByIndex_Exception = Child process exited abnormally. +* kwsysProcess_StateByIndex_Exited = Child process exited normally. +* kwsysProcess_StateByIndex_Error = Error getting the child return code. +*/ +kwsysEXPORT int kwsysProcess_GetStateByIndex(kwsysProcess* cp, int idx); +enum kwsysProcess_StateByIndex_e +{ + kwsysProcess_StateByIndex_Starting = kwsysProcess_State_Starting, + kwsysProcess_StateByIndex_Exception = kwsysProcess_State_Exception, + kwsysProcess_StateByIndex_Exited = kwsysProcess_State_Exited, + kwsysProcess_StateByIndex_Error = kwsysProcess_State_Error +}; + +/** +* When GetState returns "Exception", this method returns a +* platform-independent description of the exceptional behavior that +* caused the child to terminate abnormally. Possible exceptions are: +* +* kwsysProcess_Exception_None = No exceptional behavior occurred. +* kwsysProcess_Exception_Fault = Child crashed with a memory fault. +* kwsysProcess_Exception_Illegal = Child crashed with an illegal +* instruction. +* kwsysProcess_Exception_Interrupt = Child was interrupted by user +* (Cntl-C/Break). +* kwsysProcess_Exception_Numerical = Child crashed with a numerical +* exception. +* kwsysProcess_Exception_Other = Child terminated for another reason. +*/ +kwsysEXPORT int kwsysProcess_GetExitExceptionByIndex(kwsysProcess* cp, + int idx); + +/** +* When GetState returns "Exited" or "Exception", this method returns +* the platform-specific raw exit code of the process. UNIX platforms +* should use WIFEXITED/WEXITSTATUS and WIFSIGNALED/WTERMSIG to access +* this value. Windows users should compare the value to the various +* EXCEPTION_* values. +* +* If GetState returns "Exited", use GetExitValue to get the +* platform-independent child return value. +*/ +kwsysEXPORT int kwsysProcess_GetExitCodeByIndex(kwsysProcess* cp, int idx); + +/** +* When GetState returns "Exited", this method returns the child's +* platform-independent exit code (such as the value returned by the +* child's main). +*/ +kwsysEXPORT int kwsysProcess_GetExitValueByIndex(kwsysProcess* cp, int idx); + +/** +* When GetState returns "Exception", this method returns a string +* describing the problem. Otherwise, it returns NULL. +*/ +kwsysEXPORT const char* kwsysProcess_GetExceptionStringByIndex( + kwsysProcess* cp, int idx); + +/** * Start executing the child process. */ kwsysEXPORT void kwsysProcess_Execute(kwsysProcess* cp); @@ -331,7 +415,7 @@ enum kwsysProcess_Pipes_e kwsysProcess_Pipe_STDIN, kwsysProcess_Pipe_STDOUT, kwsysProcess_Pipe_STDERR, - kwsysProcess_Pipe_Timeout=255 + kwsysProcess_Pipe_Timeout = 255 }; /** @@ -355,12 +439,28 @@ enum kwsysProcess_Pipes_e kwsysEXPORT int kwsysProcess_WaitForExit(kwsysProcess* cp, double* timeout); /** + * Interrupt the process group for the child process that is currently + * running by sending it the appropriate operating-system specific signal. + * The caller should call WaitForExit after this returns to wait for the + * child to terminate. + * + * WARNING: If you didn't specify kwsysProcess_Option_CreateProcessGroup, + * you will interrupt your own process group. + */ +kwsysEXPORT void kwsysProcess_Interrupt(kwsysProcess* cp); + +/** * Forcefully terminate the child process that is currently running. * The caller should call WaitForExit after this returns to wait for * the child to terminate. */ kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp); +/** + * Reset the start time of the child process to the current time. + */ +kwsysEXPORT void kwsysProcess_ResetStartTime(kwsysProcess* cp); + #if defined(__cplusplus) } /* extern "C" */ #endif @@ -368,61 +468,65 @@ kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp); /* If we are building a kwsys .c or .cxx file, let it use these macros. Otherwise, undefine them to keep the namespace clean. */ #if !defined(KWSYS_NAMESPACE) -# undef kwsys_ns -# undef kwsysEXPORT -# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS -# undef kwsysProcess -# undef kwsysProcess_s -# undef kwsysProcess_New -# undef kwsysProcess_Delete -# undef kwsysProcess_SetCommand -# undef kwsysProcess_AddCommand -# undef kwsysProcess_SetTimeout -# undef kwsysProcess_SetWorkingDirectory -# undef kwsysProcess_SetPipeFile -# undef kwsysProcess_SetPipeNative -# undef kwsysProcess_SetPipeShared -# undef kwsysProcess_Option_Detach -# undef kwsysProcess_Option_HideWindow -# undef kwsysProcess_Option_Verbatim -# undef kwsysProcess_GetOption -# undef kwsysProcess_SetOption -# undef kwsysProcess_Option_e -# undef kwsysProcess_State_Starting -# undef kwsysProcess_State_Error -# undef kwsysProcess_State_Exception -# undef kwsysProcess_State_Executing -# undef kwsysProcess_State_Exited -# undef kwsysProcess_State_Expired -# undef kwsysProcess_State_Killed -# undef kwsysProcess_State_Disowned -# undef kwsysProcess_GetState -# undef kwsysProcess_State_e -# undef kwsysProcess_Exception_None -# undef kwsysProcess_Exception_Fault -# undef kwsysProcess_Exception_Illegal -# undef kwsysProcess_Exception_Interrupt -# undef kwsysProcess_Exception_Numerical -# undef kwsysProcess_Exception_Other -# undef kwsysProcess_GetExitException -# undef kwsysProcess_Exception_e -# undef kwsysProcess_GetExitCode -# undef kwsysProcess_GetExitValue -# undef kwsysProcess_GetErrorString -# undef kwsysProcess_GetExceptionString -# undef kwsysProcess_Execute -# undef kwsysProcess_Disown -# undef kwsysProcess_WaitForData -# undef kwsysProcess_Pipes_e -# undef kwsysProcess_Pipe_None -# undef kwsysProcess_Pipe_STDIN -# undef kwsysProcess_Pipe_STDOUT -# undef kwsysProcess_Pipe_STDERR -# undef kwsysProcess_Pipe_Timeout -# undef kwsysProcess_Pipe_Handle -# undef kwsysProcess_WaitForExit -# undef kwsysProcess_Kill -# endif +#undef kwsys_ns +#undef kwsysEXPORT +#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS +#undef kwsysProcess +#undef kwsysProcess_s +#undef kwsysProcess_New +#undef kwsysProcess_Delete +#undef kwsysProcess_SetCommand +#undef kwsysProcess_AddCommand +#undef kwsysProcess_SetTimeout +#undef kwsysProcess_SetWorkingDirectory +#undef kwsysProcess_SetPipeFile +#undef kwsysProcess_SetPipeNative +#undef kwsysProcess_SetPipeShared +#undef kwsysProcess_Option_Detach +#undef kwsysProcess_Option_HideWindow +#undef kwsysProcess_Option_MergeOutput +#undef kwsysProcess_Option_Verbatim +#undef kwsysProcess_Option_CreateProcessGroup +#undef kwsysProcess_GetOption +#undef kwsysProcess_SetOption +#undef kwsysProcess_Option_e +#undef kwsysProcess_State_Starting +#undef kwsysProcess_State_Error +#undef kwsysProcess_State_Exception +#undef kwsysProcess_State_Executing +#undef kwsysProcess_State_Exited +#undef kwsysProcess_State_Expired +#undef kwsysProcess_State_Killed +#undef kwsysProcess_State_Disowned +#undef kwsysProcess_GetState +#undef kwsysProcess_State_e +#undef kwsysProcess_Exception_None +#undef kwsysProcess_Exception_Fault +#undef kwsysProcess_Exception_Illegal +#undef kwsysProcess_Exception_Interrupt +#undef kwsysProcess_Exception_Numerical +#undef kwsysProcess_Exception_Other +#undef kwsysProcess_GetExitException +#undef kwsysProcess_Exception_e +#undef kwsysProcess_GetExitCode +#undef kwsysProcess_GetExitValue +#undef kwsysProcess_GetErrorString +#undef kwsysProcess_GetExceptionString +#undef kwsysProcess_Execute +#undef kwsysProcess_Disown +#undef kwsysProcess_WaitForData +#undef kwsysProcess_Pipes_e +#undef kwsysProcess_Pipe_None +#undef kwsysProcess_Pipe_STDIN +#undef kwsysProcess_Pipe_STDOUT +#undef kwsysProcess_Pipe_STDERR +#undef kwsysProcess_Pipe_Timeout +#undef kwsysProcess_Pipe_Handle +#undef kwsysProcess_WaitForExit +#undef kwsysProcess_Interrupt +#undef kwsysProcess_Kill +#undef kwsysProcess_ResetStartTime +#endif #endif #endif |