Skip to content

Commit 8934c1e

Browse files
author
Daniel Beulshausen
committed
fix some popen trouble
1 parent 512f6af commit 8934c1e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

TSRM/tsrm_win32.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ static void tsrm_win32_ctor(tsrm_win32_globals *globals)
4040
{
4141
globals->process = NULL;
4242
globals->process_size = 0;
43+
globals->comspec = _strdup((GetVersion()<0x80000000)?"cmd.exe":"command.com");
4344
}
4445

4546
static void tsrm_win32_dtor(tsrm_win32_globals *globals)
4647
{
4748
if (globals->process != NULL) {
4849
free(globals->process);
4950
}
51+
free(globals->comspec);
5052
}
5153

5254
TSRM_API void tsrm_win32_startup(void)
@@ -102,7 +104,9 @@ TSRM_API FILE* popen(const char *command, const char *type)
102104
PROCESS_INFORMATION process;
103105
SECURITY_ATTRIBUTES security;
104106
HANDLE in, out;
107+
char *cmd;
105108
ProcessPair *proc;
109+
TWLS_FETCH();
106110

107111
security.nLength = sizeof(SECURITY_ATTRIBUTES);
108112
security.bInheritHandle = TRUE;
@@ -131,10 +135,12 @@ TSRM_API FILE* popen(const char *command, const char *type)
131135
startup.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
132136
}
133137

134-
135-
if (!CreateProcess(NULL, (LPTSTR)command, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process)) {
138+
cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+4);
139+
sprintf(cmd, "%s /c %s", TWG(comspec), command);
140+
if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process)) {
136141
return NULL;
137142
}
143+
free(cmd);
138144

139145
CloseHandle(process.hThread);
140146
proc = process_get(NULL);

TSRM/tsrm_win32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct {
3434
typedef struct {
3535
ProcessPair *process;
3636
int process_size;
37+
char *comspec;
3738
} tsrm_win32_globals;
3839

3940
#ifdef ZTS

0 commit comments

Comments
 (0)