static int pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) {
- DWORD dwExitCode;
+ DWORD dwExitCode = 0;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
char *p;
struct linebuf lbuf;
- input = skip_whitespace (input);
-
- /*for (p = input; !isspace ((int) *p); p++) {
-
- if (*p == '/') {
- *p = '\\';
- }
+ int internal = 0;
- }*/
+ input = skip_whitespace (input);
if ((p = strchr (input, ' '))) {
if (!(p = strchr (lpApplicationName, '\\'))) {
- unsigned long count = sizeof (internal_commands) / sizeof (internal_commands[0]), i;
+ unsigned long count = sizeof (internal_commands) / sizeof (internal_commands[0]) - 1;
+ unsigned long i;
for (i = 0; i < count; i++) {
sprintf (lpCommandLine, "/C %s", input);
lpApplicationName = xstrdup (getenv ("COMSPEC"));
+ internal = 1;
+
break;
}
}
- }/* else {
+ }
- if (lpApplicationName) {
- free (lpApplicationName);
+ if (!internal) {
+
+ if (!lpCommandLine) {
+ lpCommandLine = xstrdup ("");
}
- lpApplicationName = 0;
+ p = xmalloc (strlen (lpApplicationName) + strlen (lpCommandLine) + 8);
+ sprintf (p, "/C %s %s", lpApplicationName, lpCommandLine);
+
+ free (lpCommandLine);
+ lpCommandLine = p;
- }*/
+ }
memset (&sa, 0, sizeof (sa));
memset (&si, 0, sizeof (si));
exit (EXIT_FAILURE);
}
-
+ /*
if (!SetHandleInformation (hStdInPipeRead, HANDLE_FLAG_INHERIT, 0)) {
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
exit (EXIT_FAILURE);
}
-
+ */
if (!CreatePipe (&hStdOutPipeRead, &hStdOutPipeWrite, &sa, 0)) {
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
si.dwFlags |= STARTF_USESTDHANDLES;
- if (!CreateProcess (lpApplicationName, lpCommandLine, 0, 0, 1, 0, 0, 0, &si, &pi)) {
+ if (!CreateProcess (getenv ("COMSPEC"), lpCommandLine, 0, 0, 1, 0, 0, 0, &si, &pi)) {
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
CloseHandle (hStdOutPipeWrite);
CloseHandle (hStdInPipeRead);
+ CloseHandle (hStdInPipeWrite);
/*WaitForSingleObject (pi.hProcess, INFINITE);*/
lbuf.start = xmalloc (lbuf.size = 256);
}
- CloseHandle (hStdOutPipeRead);
- CloseHandle (hStdInPipeWrite);
-
GetExitCodeProcess (pi.hProcess, &dwExitCode);
+ WaitForSingleObject (pi.hProcess, INFINITE);
+
+ CloseHandle (hStdOutPipeRead);
CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);