1 #ifndef __SUBCMD_RUN_COMMAND_H
2 #define __SUBCMD_RUN_COMMAND_H
7 ERR_RUN_COMMAND_FORK
= 10000,
10 ERR_RUN_COMMAND_WAITPID
,
11 ERR_RUN_COMMAND_WAITPID_WRONG_PID
,
12 ERR_RUN_COMMAND_WAITPID_SIGNAL
,
13 ERR_RUN_COMMAND_WAITPID_NOEXIT
,
15 #define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK)
17 struct child_process
{
21 * Using .in, .out, .err:
22 * - Specify 0 for no redirections (child inherits stdin, stdout,
23 * stderr from parent).
24 * - Specify -1 to have a pipe allocated as follows:
25 * .in: returns the writable pipe end; parent writes to it,
26 * the readable pipe end becomes child's stdin
27 * .out, .err: returns the readable pipe end; parent reads from
28 * it, the writable pipe end becomes child's stdout/stderr
29 * The caller of start_command() must close the returned FDs
30 * after it has completed reading from/writing to it!
31 * - Specify > 0 to set a channel to a particular FD as follows:
32 * .in: a readable FD, becomes child's stdin
33 * .out: a writable FD, becomes child's stdout/stderr
34 * .err > 0 not supported
35 * The specified FD is closed by start_command(), even in case
42 const char *const *env
;
46 unsigned exec_cmd
:1; /* if this is to be external sub-command */
47 unsigned stdout_to_stderr
:1;
48 void (*preexec_cb
)(void);
51 int start_command(struct child_process
*);
52 int finish_command(struct child_process
*);
53 int run_command(struct child_process
*);
55 #define RUN_COMMAND_NO_STDIN 1
56 #define RUN_EXEC_CMD 2 /*If this is to be external sub-command */
57 #define RUN_COMMAND_STDOUT_TO_STDERR 4
58 int run_command_v_opt(const char **argv
, int opt
);
60 #endif /* __SUBCMD_RUN_COMMAND_H */