process.h File Reference
`#include <gwenhywfar/gwenhywfarapi.h>`
`#include <gwenhywfar/types.h>`
`#include <gwenhywfar/syncio.h>`
`#include <gwenhywfar/error.h>`

Go to the source code of this file.

## Macros

#define | GWEN_PROCESS_FLAGS_DEFAULT 0
#define | GWEN_PROCESS_FLAGS_REDIR_STDERR 0x00000004
#define | GWEN_PROCESS_FLAGS_REDIR_STDIN 0x00000001
#define | GWEN_PROCESS_FLAGS_REDIR_STDOUT 0x00000002

## Typedefs

typedef struct GWEN_PROCESS | GWEN_PROCESS

## Enumerations

enum | GWEN_PROCESS_STATE { GWEN_ProcessStateNotStarted =0 , GWEN_ProcessStateRunning , GWEN_ProcessStateExited , GWEN_ProcessStateAborted , GWEN_ProcessStateStopped , GWEN_ProcessStateUnknown }

## Functions

GWENHYWFAR_API void | GWEN_Process_AddFlags (GWEN_PROCESS *pr, uint32_t f)
GWENHYWFAR_API GWEN_PROCESS_STATE | GWEN_Process_CheckState (GWEN_PROCESS *pr)
GWENHYWFAR_API void | GWEN_Process_free (GWEN_PROCESS *pr)
GWENHYWFAR_API uint32_t | GWEN_Process_GetFlags (const GWEN_PROCESS *pr)
GWENHYWFAR_API const char * | GWEN_Process_GetFolder (const GWEN_PROCESS *pr)
GWENHYWFAR_API int | GWEN_Process_GetResult (GWEN_PROCESS *pr)
GWENHYWFAR_API GWEN_SYNCIO * | GWEN_Process_GetStderr (const GWEN_PROCESS *pr)
GWENHYWFAR_API GWEN_SYNCIO * | GWEN_Process_GetStdin (const GWEN_PROCESS *pr)
GWENHYWFAR_API GWEN_SYNCIO * | GWEN_Process_GetStdout (const GWEN_PROCESS *pr)
GWENHYWFAR_API GWEN_PROCESS * | GWEN_Process_new (void)
GWENHYWFAR_API int | GWEN_Process_RunCommandWaitAndGather (const char *prg, const char *args, GWEN_BUFFER *stdOutBuffer, GWEN_BUFFER *stdErrBuffer)
GWENHYWFAR_API void | GWEN_Process_SetFilenameStdErr (GWEN_PROCESS *pr, const char *s)
GWENHYWFAR_API void | GWEN_Process_SetFilenameStdIn (GWEN_PROCESS *pr, const char *s)
GWENHYWFAR_API void | GWEN_Process_SetFilenameStdOut (GWEN_PROCESS *pr, const char *s)
GWENHYWFAR_API void | GWEN_Process_SetFlags (GWEN_PROCESS *pr, uint32_t f)
GWENHYWFAR_API void | GWEN_Process_SetFolder (GWEN_PROCESS *pr, const char *s)
GWENHYWFAR_API GWEN_PROCESS_STATE | GWEN_Process_Start (GWEN_PROCESS *pr, const char *prg, const char *args)
GWENHYWFAR_API void | GWEN_Process_SubFlags (GWEN_PROCESS *pr, uint32_t f)
GWENHYWFAR_API int | GWEN_Process_Terminate (GWEN_PROCESS *pr)
GWENHYWFAR_API int | GWEN_Process_Wait (GWEN_PROCESS *pr)

## Macro Definition Documentation

## GWEN_PROCESS_FLAGS_DEFAULT

#define GWEN_PROCESS_FLAGS_DEFAULT 0

Definition at line 42 of file process.h.

## GWEN_PROCESS_FLAGS_REDIR_STDERR

#define GWEN_PROCESS_FLAGS_REDIR_STDERR 0x00000004

redirect the child processes stderr channel

Definition at line 40 of file process.h.

## GWEN_PROCESS_FLAGS_REDIR_STDIN

#define GWEN_PROCESS_FLAGS_REDIR_STDIN 0x00000001

redirect the child processes stdin channel

Definition at line 36 of file process.h.

## GWEN_PROCESS_FLAGS_REDIR_STDOUT

#define GWEN_PROCESS_FLAGS_REDIR_STDOUT 0x00000002

redirect the child processes stdout channel

Definition at line 38 of file process.h.

## Typedef Documentation

## GWEN_PROCESS

typedef struct GWEN_PROCESS GWEN_PROCESS

Definition at line 49 of file process.h.

## Enumeration Type Documentation

## GWEN_PROCESS_STATE

enum GWEN_PROCESS_STATE

States a process can assume.

Enumerator
GWEN_ProcessStateNotStarted | process has not yet been started
GWEN_ProcessStateRunning | process is running
GWEN_ProcessStateExited | process exited normally
GWEN_ProcessStateAborted | process terminated abnormally (on POSIX systems this is in most cases an uncaught signal)
GWEN_ProcessStateStopped | process has been stopped (unused for now)
GWEN_ProcessStateUnknown | process is in an unknown state

Definition at line 54 of file process.h.

## Function Documentation

## GWEN_Process_AddFlags()

GWENHYWFAR_API void GWEN_Process_AddFlags | ( | GWEN_PROCESS * | pr,
|  | uint32_t | f )

Adds the given flag to the current process flags (see GWEN_PROCESS_FLAGS_REDIR_STDOUT and others)

References GWENHYWFAR_API.

## GWEN_Process_CheckState()

GWENHYWFAR_API GWEN_PROCESS_STATE GWEN_Process_CheckState | ( | GWEN_PROCESS * | pr | ) |

Checks for the current state of the given process.

References GWENHYWFAR_API.

## GWEN_Process_free()

GWENHYWFAR_API void GWEN_Process_free | ( | GWEN_PROCESS * | pr | ) |

Frees process data. This does not stop the process represented by this data. You should only free this data after the process has terminated or if you are not interested in the result of the process (because after freeing this data there is no way to communicate with the process).

References GWENHYWFAR_API.

## GWEN_Process_GetFlags()

GWENHYWFAR_API uint32_t GWEN_Process_GetFlags | ( | const GWEN_PROCESS * | pr | ) |

Returns the current process flags (see GWEN_PROCESS_FLAGS_REDIR_STDOUT and others)

References GWENHYWFAR_API.

## GWEN_Process_GetFolder()

GWENHYWFAR_API const char * GWEN_Process_GetFolder | ( | const GWEN_PROCESS * | pr | ) |

Get working dir for the new process.

References GWENHYWFAR_API.

## GWEN_Process_GetResult()

GWENHYWFAR_API int GWEN_Process_GetResult | ( | GWEN_PROCESS * | pr | ) |

Returns the result of a process. This process must have terminated in order to return a result.

References GWENHYWFAR_API.

## GWEN_Process_GetStderr()

GWENHYWFAR_API GWEN_SYNCIO * GWEN_Process_GetStderr | ( | const GWEN_PROCESS * | pr | ) |

Returns a GWEN_BUFFEREDIO which can be used to read data written by the process via stderr. Returns 0 if the process does not have the flag GWEN_PROCESS_FLAGS_REDIR_STDERR set.

References GWENHYWFAR_API.

## GWEN_Process_GetStdin()

GWENHYWFAR_API GWEN_SYNCIO * GWEN_Process_GetStdin | ( | const GWEN_PROCESS * | pr | ) |

Returns a GWEN_BUFFEREDIO which can be used to write data to be received by the process via stdin. Returns 0 if the process does not have the flag GWEN_PROCESS_FLAGS_REDIR_STDIN set.

References GWENHYWFAR_API.

## GWEN_Process_GetStdout()

GWENHYWFAR_API GWEN_SYNCIO * GWEN_Process_GetStdout | ( | const GWEN_PROCESS * | pr | ) |

Returns a GWEN_BUFFEREDIO which can be used to read data written by the process via stdout. Returns 0 if the process does not have the flag GWEN_PROCESS_FLAGS_REDIR_STDOUT set.

References GWENHYWFAR_API.

## GWEN_Process_new()

GWENHYWFAR_API GWEN_PROCESS * GWEN_Process_new | ( | void |  | ) |

Creates a process representation. This does not start a process, it simply prepares some data for starting a process.

References GWENHYWFAR_API.

## GWEN_Process_RunCommandWaitAndGather()

GWENHYWFAR_API int GWEN_Process_RunCommandWaitAndGather | ( | const char * | prg,
|  | const char * | args,
|  | GWEN_BUFFER * | stdOutBuffer,
|  | GWEN_BUFFER * | stdErrBuffer )

Start a process which executes the given command with the given arguments, and gathers stdout of the process into the given buffer (if any).

Your application needs to install a signal handler which catches SIGCHLD.

Returns
  result of the command (negative value: GWEN error code)

Parameters

  prg | name of the binary to run
  args | arguments for the command (all in one string, words separated by blanks)
  stdOutBuffer | buffer to receive stdout from the started process

## GWEN_Process_SetFilenameStdErr()

GWENHYWFAR_API void GWEN_Process_SetFilenameStdErr | ( | GWEN_PROCESS * | pr,
|  | const char * | s )

References GWENHYWFAR_API.

## GWEN_Process_SetFilenameStdIn()

GWENHYWFAR_API void GWEN_Process_SetFilenameStdIn | ( | GWEN_PROCESS * | pr,
|  | const char * | s )

References GWENHYWFAR_API.

## GWEN_Process_SetFilenameStdOut()

GWENHYWFAR_API void GWEN_Process_SetFilenameStdOut | ( | GWEN_PROCESS * | pr,
|  | const char * | s )

References GWENHYWFAR_API.

## GWEN_Process_SetFlags()

GWENHYWFAR_API void GWEN_Process_SetFlags | ( | GWEN_PROCESS * | pr,
|  | uint32_t | f )

Sets the process flags to the given value (see GWEN_PROCESS_FLAGS_REDIR_STDOUT and others)

References GWENHYWFAR_API.

## GWEN_Process_SetFolder()

GWENHYWFAR_API void GWEN_Process_SetFolder | ( | GWEN_PROCESS * | pr,
|  | const char * | s )

Set working dir for the new process.

## GWEN_Process_Start()

GWENHYWFAR_API GWEN_PROCESS_STATE GWEN_Process_Start | ( | GWEN_PROCESS * | pr,
|  | const char * | prg,
|  | const char * | args )

Starts the given process.

Parameters

  pr | pointer to process data
  prg | path and name of the program to start
  args | command line arguments for the program (MUST NOT contain the name of the program)

References GWENHYWFAR_API.

## GWEN_Process_SubFlags()

GWENHYWFAR_API void GWEN_Process_SubFlags | ( | GWEN_PROCESS * | pr,
|  | uint32_t | f )

Removes the given flag from the current process flags (see GWEN_PROCESS_FLAGS_REDIR_STDOUT and others)

References GWENHYWFAR_API.

## GWEN_Process_Terminate()

GWENHYWFAR_API int GWEN_Process_Terminate | ( | GWEN_PROCESS * | pr | ) |

Terminates a process immediately (on POSIX systems this is performed by sending a KILL signal). This function waits for the process to terminate.

References GWENHYWFAR_API.

## GWEN_Process_Wait()

GWENHYWFAR_API int GWEN_Process_Wait | ( | GWEN_PROCESS * | pr | ) |

Waits for the termination of the given process.

References GWENHYWFAR_API.