5c21a4733bc69d973500f1d906bd1cb6b65d376a
2 * START.C - start internal command.
7 * 24-Jul-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
10 * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
11 * Remove all hardcode string to En.rc
17 #ifdef INCLUDE_CMD_START
20 INT
cmd_start (LPTSTR first
, LPTSTR rest
)
22 TCHAR szFullName
[MAX_PATH
];
26 if (_tcsncmp (rest
, _T("/?"), 2) == 0)
28 ConOutResPuts(STRING_START_HELP1
);
32 /* check for a drive change */
33 if (!_tcscmp (first
+ 1, _T(":")) && _istalpha (*first
))
35 TCHAR szPath
[MAX_PATH
];
37 _tcscpy (szPath
, _T("A:"));
38 szPath
[0] = _totupper (*first
);
39 SetCurrentDirectory (szPath
);
40 GetCurrentDirectory (MAX_PATH
, szPath
);
41 if (szPath
[0] != (TCHAR
)_totupper (*first
))
42 ConErrPuts (INVALIDDRIVE
);
49 // FIXME: use comspec instead
53 /* get the PATH environment variable and parse it */
54 /* search the PATH environment variable for the binary */
55 param
= _tcschr( rest
, _T(' ') ); // skip program name to reach parameters
62 if (!SearchForExecutable (rest
, szFullName
))
68 /* check if this is a .BAT or .CMD file */
69 if (!_tcsicmp (_tcsrchr (szFullName
, _T('.')), _T(".bat")) ||
70 !_tcsicmp (_tcsrchr (szFullName
, _T('.')), _T(".cmd")))
73 DebugPrintf (_T("[BATCH: %s %s]\n"), szFullName
, rest
);
76 ConErrResPuts(STRING_START_ERROR1
);
80 /* exec the program */
81 TCHAR szFullCmdLine
[CMDLINE_LENGTH
];
82 PROCESS_INFORMATION prci
;
86 DebugPrintf (_T("[EXEC: %s %s]\n"), szFullName
, rest
);
88 /* build command line for CreateProcess() */
89 _tcscpy (szFullCmdLine
, first
);
92 _tcscat(szFullCmdLine
, _T(" ") );
93 _tcscat (szFullCmdLine
, param
);
96 /* fill startup info */
97 memset (&stui
, 0, sizeof (STARTUPINFO
));
98 stui
.cb
= sizeof (STARTUPINFO
);
99 stui
.dwFlags
= STARTF_USESHOWWINDOW
;
100 stui
.wShowWindow
= SW_SHOWDEFAULT
;
102 if (CreateProcess (szFullName
, szFullCmdLine
, NULL
, NULL
, FALSE
,
103 CREATE_NEW_CONSOLE
, NULL
, NULL
, &stui
, &prci
))
108 WaitForSingleObject (prci
.hProcess
, INFINITE
);
109 GetExitCodeProcess (prci
.hProcess
, &dwExitCode
);
110 nErrorLevel
= (INT
)dwExitCode
;
112 CloseHandle (prci
.hThread
);
113 CloseHandle (prci
.hProcess
);
114 /* Get New code page if it has change */
115 InputCodePage
= GetConsoleCP();
116 OutputCodePage
= GetConsoleOutputCP();
120 ErrorMessage(GetLastError (),
121 _T("Error executing CreateProcess()!!\n"));