34
* For systems where system() and popen() do not follow SHELL:
35
* 1. Write command to temp file. Temp filename must have slashes
36
* compatible with SHELL (if set) or COMSPEC.
37
* 2. Convert slashes in SHELL (if present) to be compatible with COMSPEC.
38
* Currently, only MSC (running under DOS) and MINGW versions are managed.
41
#if defined(_MSC_VER) || defined(__MINGW32__)
47
static char *shell[] = {"sh", "bash", "csh", "tcsh", "sh32", "sh16", "ksh", NULL};
48
char **shellp = shell, *s, *q;
50
if (p == NULL) return (0);
52
if ((q = strrchr(p, '\\')) != NULL)
54
if ((q = strrchr(p, '/')) != NULL)
56
if ((q = strchr(p, '.')) != NULL)
60
if (strcmp(*shellp, p) == 0) break;
63
return(*shellp ? 1 : 0);
71
while (s = strchr(p, '\\')) *s = '/';
73
while (s = strchr(p, '/')) *s = '\\';
82
char *cmd, *name, *s, *p;
85
if((name = tempnam(".", "pip")) == NULL) return(NULL);
86
p = getenv("COMSPEC"); s = getenv("SHELL");
87
cmd = malloc(strlen(name) + (s ? strlen(s) : 0) + 9); *cmd = '\0';
89
slashify(strcpy(cmd, s), p);
94
realloc(name, strlen(name) + 5);
97
if (s) sprintf(cmd + strlen(cmd), " %cc ", unixshell(s) ? '-' : '/');
98
strcpy(p = cmd + strlen(cmd), name); free(name);
101
if ( ((fp = fopen(p, "wb")) == NULL) || (fwrite(command, 1, i, fp) < i)
102
|| (fputc('\n', fp) == EOF)) {
115
if (s = strrchr(cmd, ' '))
119
unlink(s); free(cmd);
130
if (_osmode == OS2_MODE)
134
if ((cmd = scriptify(cmd)) == NULL) return(1);
135
if (s = getenv("SHELL"))
136
i = spawnlp(P_WAIT, s, s, cmd + strlen(s), NULL);
139
unlink_and_free(cmd);
143
#define os_system(cmd) system(cmd)
28
148
os_popen( char *command, char *mode ) {
107
244
if ((fd = dup(fileno(stdin))) != -1) {
108
245
if (current = freopen(pipes[cur].name, "r", stdin)) {
109
rval = system(pipes[cur].command);
246
rval = os_system(pipes[cur].command);
111
248
if (dup2(fd, fileno(stdin)) == -1) rval = -1;