2 * Copyright (C) 1996-2000 Michael R. Elkins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 /* Invokes a commmand on a pipe and optionally connects its stdin and stdout
26 * to the specified handles.
29 mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err,
30 int fdin, int fdout, int fderr)
32 int pin[2], pout[2], perr[2], thepid;
44 if (pipe (pout) == -1)
58 if (pipe (perr) == -1)
74 mutt_block_signals_system ();
76 if ((thepid = fork ()) == 0)
78 mutt_unblock_signals_system (0);
110 else if (fderr != -1)
116 execl (EXECSHELL, "sh", "-c", cmd, NULL);
119 else if (thepid == -1)
121 mutt_unblock_signals_system (1);
147 *out = fdopen (pout[0], "r");
153 *in = fdopen (pin[1], "w");
159 *err = fdopen (perr[0], "r");
165 pid_t mutt_create_filter (const char *s, FILE **in, FILE **out, FILE **err)
167 return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1));
170 int mutt_wait_filter (pid_t pid)
174 waitpid (pid, &rc, 0);
175 mutt_unblock_signals_system (1);
176 rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;