2 * START.C - start internal command.
7 * 24-Jul-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
13 #ifdef INCLUDE_CMD_START
23 INT cmd_start (LPTSTR first, LPTSTR rest)
25 TCHAR szFullName[MAX_PATH];
29 if (_tcsncmp (rest, _T("/?"), 2) == 0)
31 ConOutPuts (_T("Starts a command.\n\n"
33 " command Specifies the command to run.\n\n"
34 "At the moment all commands are started asynchronously.\n"));
39 /* check for a drive change */
40 if (!_tcscmp (first + 1, _T(":")) && _istalpha (*first))
42 TCHAR szPath[MAX_PATH];
44 _tcscpy (szPath, _T("A:"));
45 szPath[0] = _totupper (*first);
46 SetCurrentDirectory (szPath);
47 GetCurrentDirectory (MAX_PATH, szPath);
48 if (szPath[0] != (TCHAR)_totupper (*first))
49 ConErrPuts (INVALIDDRIVE);
55 // FIXME: use comspec instead
58 /* get the PATH environment variable and parse it */
59 /* search the PATH environment variable for the binary */
60 param = _tcschr( rest, _T(' ') ); // skip program name to reach parameters
66 if (!SearchForExecutable (rest, szFullName))
71 /* check if this is a .BAT or .CMD file */
72 if (!_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".bat")) ||
73 !_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".cmd")))
76 DebugPrintf (_T("[BATCH: %s %s]\n"), szFullName, rest);
78 ConErrPuts (_T("No batch support at the moment!"));
82 /* exec the program */
83 TCHAR szFullCmdLine [CMDLINE_LENGTH];
84 PROCESS_INFORMATION prci;
88 DebugPrintf (_T("[EXEC: %s %s]\n"), szFullName, rest);
90 /* build command line for CreateProcess() */
91 _tcscpy (szFullCmdLine, first);
94 _tcscat(szFullCmdLine, _T(" ") );
95 _tcscat (szFullCmdLine, param);
98 /* fill startup info */
99 memset (&stui, 0, sizeof (STARTUPINFO));
100 stui.cb = sizeof (STARTUPINFO);
101 stui.dwFlags = STARTF_USESHOWWINDOW;
102 stui.wShowWindow = SW_SHOWDEFAULT;
104 if (CreateProcess (szFullName, szFullCmdLine, NULL, NULL, FALSE,
105 CREATE_NEW_CONSOLE, NULL, NULL, &stui, &prci))
110 WaitForSingleObject (prci.hProcess, INFINITE);
111 GetExitCodeProcess (prci.hProcess, &dwExitCode);
112 nErrorLevel = (INT)dwExitCode;
114 CloseHandle (prci.hThread);
115 CloseHandle (prci.hProcess);
119 ErrorMessage (GetLastError (),
120 _T("Error executing CreateProcess()!!\n"));