13
# include <sys/wait.h>
14
# define tst(a,b) (*mode == 'r'? (b) : (a))
17
2
#include <grass/gis.h>
23
static int popen_pid[50];
26
4
FILE *G_popen(const char *cmd, const char *mode)
37
/*setvbuf ( stdout, NULL, _IONBF, 0 ); */
39
if (_pipe(thepipes, 256, O_BINARY) != -1) {
40
execl("cmd", "cmd", "/c", cmd, (char *)NULL);
41
close(thepipes[WRITE]);
42
rv = fdopen(thepipes[READ], mode);
47
#else /* __MINGW32__ */
57
me = tst(p[WRITE], p[READ]);
58
you = tst(p[READ], p[WRITE]);
59
if ((pid = fork()) == 0) {
60
/* me and you reverse roles in child */
65
execl("/bin/sh", "sh", "-c", cmd, (char *)NULL);
74
return (fdopen(me, mode));
76
#endif /* __MINGW32__ */
6
return popen(cmd, mode);
80
9
int G_pclose(FILE * ptr)
82
RETSIGTYPE(*sigint) ();
84
RETSIGTYPE(*sighup) ();
87
RETSIGTYPE(*sigquit) ();
99
sigint = signal(SIGINT, SIG_IGN);
101
_cwait(&status, popen_pid[f], WAIT_CHILD);
108
sigquit = signal(SIGQUIT, SIG_IGN);
111
sighup = signal(SIGHUP, SIG_IGN);
113
while ((r = wait(&status)) != popen_pid[f] && r != -1) ;
117
#endif /* __MINGW32__ */
119
signal(SIGINT, sigint);
122
signal(SIGQUIT, sigquit);
125
signal(SIGHUP, sighup);