]> granicus.if.org Git - php/commitdiff
fix some popen trouble
authorDaniel Beulshausen <dbeu@php.net>
Sun, 1 Jul 2001 20:08:21 +0000 (20:08 +0000)
committerDaniel Beulshausen <dbeu@php.net>
Sun, 1 Jul 2001 20:08:21 +0000 (20:08 +0000)
TSRM/tsrm_win32.c
TSRM/tsrm_win32.h

index 1613ebea402e9f1accb9a16d792935f0b53a8cfa..47c91d381e51c1edcdb97ce3049275f1307b7a0c 100644 (file)
@@ -40,6 +40,7 @@ static void tsrm_win32_ctor(tsrm_win32_globals *globals)
 {
        globals->process = NULL;
        globals->process_size = 0;
+       globals->comspec = _strdup((GetVersion()<0x80000000)?"cmd.exe":"command.com");
 }
 
 static void tsrm_win32_dtor(tsrm_win32_globals *globals)
@@ -47,6 +48,7 @@ static void tsrm_win32_dtor(tsrm_win32_globals *globals)
        if (globals->process != NULL) {
                free(globals->process);
        }
+       free(globals->comspec);
 }
 
 TSRM_API void tsrm_win32_startup(void)
@@ -102,7 +104,9 @@ TSRM_API FILE* popen(const char *command, const char *type)
        PROCESS_INFORMATION process;
        SECURITY_ATTRIBUTES security;
        HANDLE in, out;
+       char *cmd;
        ProcessPair *proc;
+       TWLS_FETCH();
 
        security.nLength                                = sizeof(SECURITY_ATTRIBUTES);
        security.bInheritHandle                 = TRUE;
@@ -131,10 +135,12 @@ TSRM_API FILE* popen(const char *command, const char *type)
                startup.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
        }
 
-
-       if (!CreateProcess(NULL, (LPTSTR)command, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process)) {
+       cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+4);
+       sprintf(cmd, "%s /c %s", TWG(comspec), command);
+       if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process)) {
                return NULL;
        }
+       free(cmd);
 
        CloseHandle(process.hThread);
        proc = process_get(NULL);
index 08eceb644f977f383c25a4608a3971667c40998a..c26c8f950657f42293baf88942ef62c6c10a8a5b 100644 (file)
@@ -34,6 +34,7 @@ typedef struct {
 typedef struct {
        ProcessPair *process;
        int process_size;
+       char *comspec;
 } tsrm_win32_globals;
 
 #ifdef ZTS