Janitorial: C booleans must not be compared against TRUE.
[wine/multimedia.git] / programs / wcmd / wcmdmain.c
blobbd127159c7afa49b0f21c802918c9a24ad939baf
1 /*
2 * WCMD - Wine-compatible command line interface.
4 * Copyright (C) 1999 - 2001 D A Pickles
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * FIXME:
23 * - Cannot handle parameters in quotes
24 * - Lots of functionality missing from builtins
27 #include "ntstatus.h"
28 #include "wcmd.h"
30 const char *inbuilt[] = {"ATTRIB", "CALL", "CD", "CHDIR", "CLS", "COPY", "CTTY",
31 "DATE", "DEL", "DIR", "ECHO", "ERASE", "FOR", "GOTO",
32 "HELP", "IF", "LABEL", "MD", "MKDIR", "MOVE", "PATH", "PAUSE",
33 "PROMPT", "REM", "REN", "RENAME", "RD", "RMDIR", "SET", "SHIFT",
34 "TIME", "TITLE", "TYPE", "VERIFY", "VER", "VOL",
35 "ENDLOCAL", "SETLOCAL", "EXIT" };
37 HINSTANCE hinst;
38 DWORD errorlevel;
39 int echo_mode = 1, verify_mode = 0;
40 const char nyi[] = "Not Yet Implemented\n\n";
41 const char newline[] = "\n";
42 const char version_string[] = "WCMD Version 0.17\n\n";
43 const char anykey[] = "Press Return key to continue: ";
44 char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
45 BATCH_CONTEXT *context = NULL;
47 /*****************************************************************************
48 * Main entry point. This is a console application so we have a main() not a
49 * winmain().
52 int main (int argc, char *argv[])
54 char string[1024];
55 char* cmd=NULL;
56 DWORD count;
57 HANDLE h;
58 int opt_c, opt_k, opt_q;
60 argv++;
61 opt_c=opt_k=opt_q=0;
62 while (*argv!=NULL)
64 if (lstrcmpi(*argv,"/c")==0) {
65 opt_c=1;
66 argv++;
67 break;
68 } else if (lstrcmpi(*argv,"/q")==0) {
69 opt_q=1;
70 } else if (lstrcmpi(*argv,"/k")==0) {
71 opt_k=1;
72 argv++;
73 break;
74 } else if (lstrcmpi(*argv,"/t")==0 || lstrcmpi(*argv,"/x")==0 ||
75 lstrcmpi(*argv,"/y")==0) {
76 /* Ignored for compatibility with Windows */
77 } else {
78 break;
80 argv++;
83 if (opt_q) {
84 WCMD_echo("OFF");
87 if (opt_c || opt_k) {
88 int len;
89 char** arg;
90 char* p;
92 /* Build the command to execute */
93 len = 0;
94 for (arg = argv; *arg; arg++)
96 int has_space,bcount;
97 char* a;
99 has_space=0;
100 bcount=0;
101 a=*arg;
102 if( !*a ) has_space=1;
103 while (*a!='\0') {
104 if (*a=='\\') {
105 bcount++;
106 } else {
107 if (*a==' ' || *a=='\t') {
108 has_space=1;
109 } else if (*a=='"') {
110 /* doubling of '\' preceeding a '"',
111 * plus escaping of said '"'
113 len+=2*bcount+1;
115 bcount=0;
117 a++;
119 len+=(a-*arg)+1 /* for the separating space */;
120 if (has_space)
121 len+=2; /* for the quotes */
124 cmd = HeapAlloc(GetProcessHeap(), 0, len);
125 if (!cmd)
126 exit(1);
128 p = cmd;
129 for (arg = argv; *arg; arg++)
131 int has_space,has_quote;
132 char* a;
134 /* Check for quotes and spaces in this argument */
135 has_space=has_quote=0;
136 a=*arg;
137 if( !*a ) has_space=1;
138 while (*a!='\0') {
139 if (*a==' ' || *a=='\t') {
140 has_space=1;
141 if (has_quote)
142 break;
143 } else if (*a=='"') {
144 has_quote=1;
145 if (has_space)
146 break;
148 a++;
151 /* Now transfer it to the command line */
152 if (has_space)
153 *p++='"';
154 if (has_quote) {
155 int bcount;
156 char* a;
158 bcount=0;
159 a=*arg;
160 while (*a!='\0') {
161 if (*a=='\\') {
162 *p++=*a;
163 bcount++;
164 } else {
165 if (*a=='"') {
166 int i;
168 /* Double all the '\\' preceeding this '"', plus one */
169 for (i=0;i<=bcount;i++)
170 *p++='\\';
171 *p++='"';
172 } else {
173 *p++=*a;
175 bcount=0;
177 a++;
179 } else {
180 strcpy(p,*arg);
181 p+=strlen(*arg);
183 if (has_space)
184 *p++='"';
185 *p++=' ';
187 if (p > cmd)
188 p--; /* remove last space */
189 *p = '\0';
192 if (opt_c) {
193 /* If we do a "wcmd /c command", we don't want to allocate a new
194 * console since the command returns immediately. Rather, we use
195 * the currently allocated input and output handles. This allows
196 * us to pipe to and read from the command interpreter.
198 if (strchr(cmd,'|') != NULL)
199 WCMD_pipe(cmd);
200 else
201 WCMD_process_command(cmd);
202 HeapFree(GetProcessHeap(), 0, cmd);
203 return 0;
206 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT |
207 ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
208 SetConsoleTitle("Wine Command Prompt");
210 if (opt_k) {
211 WCMD_process_command(cmd);
212 HeapFree(GetProcessHeap(), 0, cmd);
216 * If there is an AUTOEXEC.BAT file, try to execute it.
219 GetFullPathName ("\\autoexec.bat", sizeof(string), string, NULL);
220 h = CreateFile (string, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
221 if (h != INVALID_HANDLE_VALUE) {
222 CloseHandle (h);
223 #if 0
224 WCMD_batch_command (string);
225 #endif
229 * Loop forever getting commands and executing them.
232 WCMD_version ();
233 while (TRUE) {
234 WCMD_show_prompt ();
235 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
236 if (count > 1) {
237 string[count-1] = '\0'; /* ReadFile output is not null-terminated! */
238 if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */
239 if (lstrlen (string) != 0) {
240 if (strchr(string,'|') != NULL) {
241 WCMD_pipe (string);
243 else {
244 WCMD_process_command (string);
252 /*****************************************************************************
253 * Process one command. If the command is EXIT this routine does not return.
254 * We will recurse through here executing batch files.
258 void WCMD_process_command (char *command)
260 char *cmd, *p;
261 int status, i, len;
262 DWORD count, creationDisposition;
263 HANDLE old_stdin = 0, old_stdout = 0, h;
264 char *whichcmd;
265 SECURITY_ATTRIBUTES sa;
268 * Expand up environment variables.
270 len = ExpandEnvironmentStrings (command, NULL, 0);
271 cmd = HeapAlloc( GetProcessHeap(), 0, len );
272 status = ExpandEnvironmentStrings (command, cmd, len);
273 if (!status) {
274 WCMD_print_error ();
275 HeapFree( GetProcessHeap(), 0, cmd );
276 return;
280 * Changing default drive has to be handled as a special case.
283 if ((cmd[1] == ':') && IsCharAlpha (cmd[0]) && (strlen(cmd) == 2)) {
284 status = SetCurrentDirectory (cmd);
285 if (!status) WCMD_print_error ();
286 HeapFree( GetProcessHeap(), 0, cmd );
287 return;
290 /* Don't issue newline WCMD_output (newline); @JED*/
292 sa.nLength = sizeof(sa);
293 sa.lpSecurityDescriptor = NULL;
294 sa.bInheritHandle = TRUE;
296 * Redirect stdin and/or stdout if required.
299 if ((p = strchr(cmd,'<')) != NULL) {
300 h = CreateFile (WCMD_parameter (++p, 0, NULL), GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING,
301 FILE_ATTRIBUTE_NORMAL, NULL);
302 if (h == INVALID_HANDLE_VALUE) {
303 WCMD_print_error ();
304 HeapFree( GetProcessHeap(), 0, cmd );
305 return;
307 old_stdin = GetStdHandle (STD_INPUT_HANDLE);
308 SetStdHandle (STD_INPUT_HANDLE, h);
310 if ((p = strchr(cmd,'>')) != NULL) {
311 *p++ = '\0';
312 if ('>' == *p) {
313 creationDisposition = OPEN_ALWAYS;
314 p++;
316 else {
317 creationDisposition = CREATE_ALWAYS;
319 h = CreateFile (WCMD_parameter (p, 0, NULL), GENERIC_WRITE, 0, &sa, creationDisposition,
320 FILE_ATTRIBUTE_NORMAL, NULL);
321 if (h == INVALID_HANDLE_VALUE) {
322 WCMD_print_error ();
323 HeapFree( GetProcessHeap(), 0, cmd );
324 return;
326 if (SetFilePointer (h, 0, NULL, FILE_END) ==
327 INVALID_SET_FILE_POINTER) {
328 WCMD_print_error ();
330 old_stdout = GetStdHandle (STD_OUTPUT_HANDLE);
331 SetStdHandle (STD_OUTPUT_HANDLE, h);
333 if ((p = strchr(cmd,'<')) != NULL) *p = '\0';
336 * Strip leading whitespaces, and a '@' if supplied
338 whichcmd = WCMD_strtrim_leading_spaces(cmd);
339 if (whichcmd[0] == '@') whichcmd++;
342 * Check if the command entered is internal. If it is, pass the rest of the
343 * line down to the command. If not try to run a program.
346 count = 0;
347 while (IsCharAlphaNumeric(whichcmd[count])) {
348 count++;
350 for (i=0; i<=WCMD_EXIT; i++) {
351 if (CompareString (LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
352 whichcmd, count, inbuilt[i], -1) == 2) break;
354 p = WCMD_strtrim_leading_spaces (&whichcmd[count]);
355 WCMD_parse (p, quals, param1, param2);
356 switch (i) {
358 case WCMD_ATTRIB:
359 WCMD_setshow_attrib ();
360 break;
361 case WCMD_CALL:
362 WCMD_batch (param1, p, 1);
363 break;
364 case WCMD_CD:
365 case WCMD_CHDIR:
366 WCMD_setshow_default ();
367 break;
368 case WCMD_CLS:
369 WCMD_clear_screen ();
370 break;
371 case WCMD_COPY:
372 WCMD_copy ();
373 break;
374 case WCMD_CTTY:
375 WCMD_change_tty ();
376 break;
377 case WCMD_DATE:
378 WCMD_setshow_date ();
379 break;
380 case WCMD_DEL:
381 case WCMD_ERASE:
382 WCMD_delete (0);
383 break;
384 case WCMD_DIR:
385 WCMD_directory ();
386 break;
387 case WCMD_ECHO:
388 WCMD_echo(&whichcmd[count]);
389 break;
390 case WCMD_FOR:
391 WCMD_for (p);
392 break;
393 case WCMD_GOTO:
394 WCMD_goto ();
395 break;
396 case WCMD_HELP:
397 WCMD_give_help (p);
398 break;
399 case WCMD_IF:
400 WCMD_if (p);
401 break;
402 case WCMD_LABEL:
403 WCMD_volume (1, p);
404 break;
405 case WCMD_MD:
406 case WCMD_MKDIR:
407 WCMD_create_dir ();
408 break;
409 case WCMD_MOVE:
410 WCMD_move ();
411 break;
412 case WCMD_PATH:
413 WCMD_setshow_path (p);
414 break;
415 case WCMD_PAUSE:
416 WCMD_pause ();
417 break;
418 case WCMD_PROMPT:
419 WCMD_setshow_prompt ();
420 break;
421 case WCMD_REM:
422 break;
423 case WCMD_REN:
424 case WCMD_RENAME:
425 WCMD_rename ();
426 break;
427 case WCMD_RD:
428 case WCMD_RMDIR:
429 WCMD_remove_dir ();
430 break;
431 case WCMD_SETLOCAL:
432 WCMD_setlocal(p);
433 break;
434 case WCMD_ENDLOCAL:
435 WCMD_endlocal();
436 break;
437 case WCMD_SET:
438 WCMD_setshow_env (p);
439 break;
440 case WCMD_SHIFT:
441 WCMD_shift ();
442 break;
443 case WCMD_TIME:
444 WCMD_setshow_time ();
445 break;
446 case WCMD_TITLE:
447 if (strlen(&whichcmd[count]) > 0)
448 WCMD_title(&whichcmd[count+1]);
449 break;
450 case WCMD_TYPE:
451 WCMD_type ();
452 break;
453 case WCMD_VER:
454 WCMD_version ();
455 break;
456 case WCMD_VERIFY:
457 WCMD_verify (p);
458 break;
459 case WCMD_VOL:
460 WCMD_volume (0, p);
461 break;
462 case WCMD_EXIT:
463 ExitProcess (0);
464 default:
465 WCMD_run_program (whichcmd);
467 HeapFree( GetProcessHeap(), 0, cmd );
468 if (old_stdin) {
469 CloseHandle (GetStdHandle (STD_INPUT_HANDLE));
470 SetStdHandle (STD_INPUT_HANDLE, old_stdin);
472 if (old_stdout) {
473 CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE));
474 SetStdHandle (STD_OUTPUT_HANDLE, old_stdout);
478 /******************************************************************************
479 * WCMD_run_program
481 * Execute a command line as an external program. If no extension given then
482 * precedence is given to .BAT files. Must allow recursion.
484 * FIXME: Case sensitivity in suffixes!
487 void WCMD_run_program (char *command) {
489 STARTUPINFO st;
490 PROCESS_INFORMATION pe;
491 SHFILEINFO psfi;
492 DWORD console;
493 BOOL status;
494 HANDLE h;
495 HINSTANCE hinst;
496 char filetorun[MAX_PATH];
498 WCMD_parse (command, quals, param1, param2); /* Quick way to get the filename */
499 if (!(*param1) && !(*param2))
500 return;
501 if (strpbrk (param1, "/\\:") == NULL) { /* No explicit path given */
502 char *ext = strrchr( param1, '.' );
503 if (!ext || !strcasecmp( ext, ".bat"))
505 if (SearchPath (NULL, param1, ".bat", sizeof(filetorun), filetorun, NULL)) {
506 WCMD_batch (filetorun, command, 0);
507 return;
510 if (!ext || !strcasecmp( ext, ".cmd"))
512 if (SearchPath (NULL, param1, ".cmd", sizeof(filetorun), filetorun, NULL)) {
513 WCMD_batch (filetorun, command, 0);
514 return;
518 else { /* Explicit path given */
519 char *ext = strrchr( param1, '.' );
520 if (ext && (!strcasecmp( ext, ".bat" ) || !strcasecmp( ext, ".cmd" )))
522 WCMD_batch (param1, command, 0);
523 return;
526 if (ext && strpbrk( ext, "/\\:" )) ext = NULL;
527 if (!ext)
529 strcpy (filetorun, param1);
530 strcat (filetorun, ".bat");
531 h = CreateFile (filetorun, GENERIC_READ, FILE_SHARE_READ,
532 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
533 if (h != INVALID_HANDLE_VALUE) {
534 CloseHandle (h);
535 WCMD_batch (param1, command, 0);
536 return;
541 /* No batch file found, assume executable */
543 hinst = FindExecutable (param1, NULL, filetorun);
544 if ((int)hinst < 32) {
545 WCMD_print_error ();
546 return;
548 console = SHGetFileInfo (filetorun, 0, &psfi, sizeof(psfi), SHGFI_EXETYPE);
549 ZeroMemory (&st, sizeof(STARTUPINFO));
550 st.cb = sizeof(STARTUPINFO);
551 status = CreateProcess (NULL, command, NULL, NULL, TRUE,
552 0, NULL, NULL, &st, &pe);
553 if (!status) {
554 WCMD_print_error ();
555 return;
557 if (!console) errorlevel = 0;
558 else
560 if (!HIWORD(console)) WaitForSingleObject (pe.hProcess, INFINITE);
561 GetExitCodeProcess (pe.hProcess, &errorlevel);
562 if (errorlevel == STILL_ACTIVE) errorlevel = 0;
564 CloseHandle(pe.hProcess);
565 CloseHandle(pe.hThread);
568 /******************************************************************************
569 * WCMD_show_prompt
571 * Display the prompt on STDout
575 void WCMD_show_prompt (void) {
577 int status;
578 char out_string[MAX_PATH], curdir[MAX_PATH], prompt_string[MAX_PATH];
579 char *p, *q;
581 status = GetEnvironmentVariable ("PROMPT", prompt_string, sizeof(prompt_string));
582 if ((status == 0) || (status > sizeof(prompt_string))) {
583 lstrcpy (prompt_string, "$P$G");
585 p = prompt_string;
586 q = out_string;
587 *q = '\0';
588 while (*p != '\0') {
589 if (*p != '$') {
590 *q++ = *p++;
591 *q = '\0';
593 else {
594 p++;
595 switch (toupper(*p)) {
596 case '$':
597 *q++ = '$';
598 break;
599 case 'B':
600 *q++ = '|';
601 break;
602 case 'D':
603 GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, q, MAX_PATH);
604 while (*q) q++;
605 break;
606 case 'E':
607 *q++ = '\E';
608 break;
609 case 'G':
610 *q++ = '>';
611 break;
612 case 'L':
613 *q++ = '<';
614 break;
615 case 'N':
616 status = GetCurrentDirectory (sizeof(curdir), curdir);
617 if (status) {
618 *q++ = curdir[0];
620 break;
621 case 'P':
622 status = GetCurrentDirectory (sizeof(curdir), curdir);
623 if (status) {
624 lstrcat (q, curdir);
625 while (*q) q++;
627 break;
628 case 'Q':
629 *q++ = '=';
630 break;
631 case 'T':
632 GetTimeFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL, q, MAX_PATH);
633 while (*q) q++;
634 break;
635 case 'V':
636 lstrcat (q, version_string);
637 while (*q) q++;
638 break;
639 case '_':
640 *q++ = '\n';
641 break;
643 p++;
644 *q = '\0';
647 WCMD_output (out_string);
650 /****************************************************************************
651 * WCMD_print_error
653 * Print the message for GetLastError
656 void WCMD_print_error (void) {
657 LPVOID lpMsgBuf;
658 DWORD error_code;
659 int status;
661 error_code = GetLastError ();
662 status = FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
663 NULL, error_code, 0, (LPTSTR) &lpMsgBuf, 0, NULL);
664 if (!status) {
665 WCMD_output ("FIXME: Cannot display message for error %d, status %d\n",
666 error_code, GetLastError());
667 return;
669 WCMD_output (lpMsgBuf);
670 LocalFree ((HLOCAL)lpMsgBuf);
671 WCMD_output (newline);
672 return;
675 /*******************************************************************
676 * WCMD_parse - parse a command into parameters and qualifiers.
678 * On exit, all qualifiers are concatenated into q, the first string
679 * not beginning with "/" is in p1 and the
680 * second in p2. Any subsequent non-qualifier strings are lost.
681 * Parameters in quotes are handled.
684 void WCMD_parse (char *s, char *q, char *p1, char *p2) {
686 int p = 0;
688 *q = *p1 = *p2 = '\0';
689 while (TRUE) {
690 switch (*s) {
691 case '/':
692 *q++ = *s++;
693 while ((*s != '\0') && (*s != ' ') && *s != '/') {
694 *q++ = toupper (*s++);
696 *q = '\0';
697 break;
698 case ' ':
699 s++;
700 break;
701 case '"':
702 s++;
703 while ((*s != '\0') && (*s != '"')) {
704 if (p == 0) *p1++ = *s++;
705 else if (p == 1) *p2++ = *s++;
706 else s++;
708 if (p == 0) *p1 = '\0';
709 if (p == 1) *p2 = '\0';
710 p++;
711 if (*s == '"') s++;
712 break;
713 case '\0':
714 return;
715 default:
716 while ((*s != '\0') && (*s != ' ')) {
717 if (p == 0) *p1++ = *s++;
718 else if (p == 1) *p2++ = *s++;
719 else s++;
721 if (p == 0) *p1 = '\0';
722 if (p == 1) *p2 = '\0';
723 p++;
728 /*******************************************************************
729 * WCMD_output - send output to current standard output device.
733 void WCMD_output (const char *format, ...) {
735 va_list ap;
736 char string[1024];
738 va_start(ap,format);
739 vsprintf (string, format, ap);
740 va_end(ap);
741 WCMD_output_asis(string);
745 static int line_count;
746 static int max_height;
747 static BOOL paged_mode;
749 void WCMD_enter_paged_mode(void)
751 CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
753 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo))
754 max_height = consoleInfo.dwSize.Y;
755 else
756 max_height = 25;
757 paged_mode = TRUE;
758 line_count = 5; /* keep 5 lines from previous output */
761 void WCMD_leave_paged_mode(void)
763 paged_mode = FALSE;
766 /*******************************************************************
767 * WCMD_output_asis - send output to current standard output device.
768 * without formatting eg. when message contains '%'
771 void WCMD_output_asis (const char *message) {
772 DWORD count;
773 char* ptr;
774 char string[1024];
776 if (paged_mode) {
777 do {
778 if ((ptr = strchr(message, '\n')) != NULL) ptr++;
779 WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), message,
780 (ptr) ? ptr - message : lstrlen(message), &count, NULL);
781 if (ptr) {
782 if (++line_count >= max_height - 1) {
783 line_count = 0;
784 WCMD_output_asis (anykey);
785 ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
788 } while ((message = ptr) != NULL);
789 } else {
790 WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), message, lstrlen(message), &count, NULL);
795 /***************************************************************************
796 * WCMD_strtrim_leading_spaces
798 * Remove leading spaces from a string. Return a pointer to the first
799 * non-space character. Does not modify the input string
802 char *WCMD_strtrim_leading_spaces (char *string) {
804 char *ptr;
806 ptr = string;
807 while (*ptr == ' ') ptr++;
808 return ptr;
811 /*************************************************************************
812 * WCMD_strtrim_trailing_spaces
814 * Remove trailing spaces from a string. This routine modifies the input
815 * string by placing a null after the last non-space character
818 void WCMD_strtrim_trailing_spaces (char *string) {
820 char *ptr;
822 ptr = string + lstrlen (string) - 1;
823 while ((*ptr == ' ') && (ptr >= string)) {
824 *ptr = '\0';
825 ptr--;
829 /*************************************************************************
830 * WCMD_pipe
832 * Handle pipes within a command - the DOS way using temporary files.
835 void WCMD_pipe (char *command) {
837 char *p;
838 char temp_path[MAX_PATH], temp_file[MAX_PATH], temp_file2[MAX_PATH], temp_cmd[1024];
840 GetTempPath (sizeof(temp_path), temp_path);
841 GetTempFileName (temp_path, "WCMD", 0, temp_file);
842 p = strchr(command, '|');
843 *p++ = '\0';
844 wsprintf (temp_cmd, "%s > %s", command, temp_file);
845 WCMD_process_command (temp_cmd);
846 command = p;
847 while ((p = strchr(command, '|'))) {
848 *p++ = '\0';
849 GetTempFileName (temp_path, "WCMD", 0, temp_file2);
850 wsprintf (temp_cmd, "%s < %s > %s", command, temp_file, temp_file2);
851 WCMD_process_command (temp_cmd);
852 DeleteFile (temp_file);
853 lstrcpy (temp_file, temp_file2);
854 command = p;
856 wsprintf (temp_cmd, "%s < %s", command, temp_file);
857 WCMD_process_command (temp_cmd);
858 DeleteFile (temp_file);