31839a19a4d0f8c94b715dcf92842b97bfaf1a21
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 ConOutResPaging(TRUE
,STRING_START_HELP1
);
34 /* check for a drive change */
35 if (!_tcscmp (first
+ 1, _T(":")) && _istalpha (*first
))
37 TCHAR szPath
[MAX_PATH
];
39 _tcscpy (szPath
, _T("A:"));
40 szPath
[0] = _totupper (*first
);
41 SetCurrentDirectory (szPath
);
42 GetCurrentDirectory (MAX_PATH
, szPath
);
43 if (szPath
[0] != (TCHAR
)_totupper (*first
))
44 ConErrResPuts (STRING_FREE_ERROR1
);
51 // FIXME: use comspec instead
55 /* get the PATH environment variable and parse it */
56 /* search the PATH environment variable for the binary */
57 param
= _tcschr( rest
, _T(' ') ); // skip program name to reach parameters
64 if (!SearchForExecutable (rest
, szFullName
))
70 /* check if this is a .BAT or .CMD file */
71 if (!_tcsicmp (_tcsrchr (szFullName
, _T('.')), _T(".bat")) ||
72 !_tcsicmp (_tcsrchr (szFullName
, _T('.')), _T(".cmd")))
75 DebugPrintf (_T("[BATCH: %s %s]\n"), szFullName
, rest
);
78 ConErrResPuts(STRING_START_ERROR1
);
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
);
116 /* Get New code page if it has change */
117 InputCodePage
= GetConsoleCP();
118 OutputCodePage
= GetConsoleOutputCP();
122 ErrorMessage(GetLastError (),
123 _T("Error executing CreateProcess()!!\n"));