Pass files through external commands (filters) More...
#include "config.h"
#include <stdbool.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include "filter.h"
#include "signal2.h"
Go to the source code of this file.
Functions | |
pid_t | filter_create_fd (const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err, int fdin, int fdout, int fderr, char **envlist) |
Run a command on a pipe (optionally connect stdin/stdout) | |
pid_t | filter_create (const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err, char **envlist) |
Set up filter program. | |
int | filter_wait (pid_t pid) |
Wait for the exit of a process and return its status. | |
Pass files through external commands (filters)
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file filter.c.
pid_t filter_create_fd | ( | const char * | cmd, |
FILE ** | fp_in, | ||
FILE ** | fp_out, | ||
FILE ** | fp_err, | ||
int | fdin, | ||
int | fdout, | ||
int | fderr, | ||
char ** | envlist | ||
) |
Run a command on a pipe (optionally connect stdin/stdout)
[in] | cmd | Command line to invoke using sh -c |
[out] | fp_in | File stream pointing to stdin for the command process, can be NULL |
[out] | fp_out | File stream pointing to stdout for the command process, can be NULL |
[out] | fp_err | File stream pointing to stderr for the command process, can be NULL |
[in] | fdin | If fp_in is NULL and fdin is not -1 then fdin will be used as stdin for the command process |
[in] | fdout | If fp_out is NULL and fdout is not -1 then fdout will be used as stdout for the command process |
[in] | fderr | If fp_err is NULL and fderr is not -1 then fderr will be used as stderr for the command process |
[in] | envlist | Environment variables |
num | PID of the created process |
-1 | Error creating pipes or forking |
This function provides multiple mechanisms to handle IO sharing for the command process. File streams are prioritized over file descriptors if present.
Additionally, fp_in, fp_out, and fp_err will point to FILE* streams representing the processes stdin, stdout, and stderr.
Definition at line 62 of file filter.c.
pid_t filter_create | ( | const char * | cmd, |
FILE ** | fp_in, | ||
FILE ** | fp_out, | ||
FILE ** | fp_err, | ||
char ** | envlist | ||
) |
Set up filter program.
[in] | cmd | Command string |
[out] | fp_in | FILE pointer of stdin |
[out] | fp_out | FILE pointer of stdout |
[out] | fp_err | FILE pointer of stderr |
[in] | envlist | Environment variables |
num | PID of filter |
Definition at line 209 of file filter.c.
int filter_wait | ( | pid_t | pid | ) |
Wait for the exit of a process and return its status.
pid | Process id of the process to wait for |
num | Exit status of the process identified by pid |
-1 | Error |
Definition at line 220 of file filter.c.