Component walkpopen
Component index
Section index

Component walkpopen


Search

Type

Function

Summary

Walk the output of a process

Description

Each lines (text) is sent to the oneline functag. It returns the number of line processed, or -1 if some errors.

void empty (const char *command)
void end ()
void fail (const char *command)
void init (FILE *fout, bool &end)
int oneerr (const char *line, const char *command, FILE *fout)
int oneline (const char *line, int noline, FILE *fout)
void start (FILE *fout, bool &end)

Examples

sample / walkpopen component

Prototypes

int walkpopen (const char *command, int timeout, bool user)

Normally walkpopen change to the root directory before executing a command. Further, it cleans up the environment. This is normally used by privileged program to avoid security hole. If you are writting an end user application (no privilege), you may want to set the parameter "user" to true to avoid this directory changing and environment variables filtering.

int walkpopen (const char *cmdname, const char *arg, int timeout)

The command name is just a name. It is looked up in the resource database to locate its path. If the path is already known, an absolute path may be specified instead.

int walkpopen (const char *cmd, int timeout)

Return the end status of the process.

Functags

void empty (const char *command) Optional

Called when the process exits without any output

void end () Optional

Called after having processed the last output line

void fail (const char *command) Optional

Called when the command failed to execute

void init (FILE *fout, bool &end) Optional

Called at the beginning of the session

This is used to send some input to the sub-process so it can start to work

int oneerr (const char *line, const char *command, FILE *fout) Optional

Is called for every error message sent by the process (every line)

This function must return 0 to continue, -1 to force walkpopen to exit.

int oneline (const char *line, int noline, FILE *fout) Mandatory

Is called for every line of text sent by the process (on standard output)

Must return -1 if we want the processing to stop.

void start (FILE *fout, bool &end) Optional

Called before processing the first output line

Fhelpers

void close_input ()

Close the input of the sub-process

After sending some information to the sub-process, we close its input. The sub-process receives an end-of-file condition and generally ends its processing.