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
];
28 if (_tcsncmp (rest
, _T("/?"), 2) == 0)
30 ConOutPuts (_T("Starts a command.\n\n"
32 " command Specifies the command to run.\n\n"
33 "At the moment all commands are started asynchronously.\n"));
38 /* check for a drive change */
39 if (!_tcscmp (first
+ 1, _T(":")) && _istalpha (*first
))
41 TCHAR szPath
[MAX_PATH
];
43 _tcscpy (szPath
, _T("A:"));
44 szPath
[0] = _totupper (*first
);
45 SetCurrentDirectory (szPath
);
46 GetCurrentDirectory (MAX_PATH
, szPath
);
47 if (szPath
[0] != (TCHAR
)_totupper (*first
))
48 ConErrPuts (INVALIDDRIVE
);
53 /* get the PATH environment variable and parse it */
54 /* search the PATH environment variable for the binary */
55 if (!SearchForExecutable (first
, szFullName
))
61 /* check if this is a .BAT or .CMD file */
62 if (!_tcsicmp (_tcsrchr (szFullName
, _T('.')), _T(".bat")) ||
63 !_tcsicmp (_tcsrchr (szFullName
, _T('.')), _T(".cmd")))
66 DebugPrintf ("[BATCH: %s %s]\n", szFullName
, rest
);
68 ConErrPuts (_T("No batch support at the moment!"));
72 /* exec the program */
73 TCHAR szFullCmdLine
[CMDLINE_LENGTH
];
74 PROCESS_INFORMATION prci
;
78 DebugPrintf ("[EXEC: %s %s]\n", szFullName
, rest
);
80 /* build command line for CreateProcess() */
81 _tcscpy (szFullCmdLine
, szFullName
);
82 _tcscat (szFullCmdLine
, _T(" "));
83 _tcscat (szFullCmdLine
, rest
);
85 /* fill startup info */
86 memset (&stui
, 0, sizeof (STARTUPINFO
));
87 stui
.cb
= sizeof (STARTUPINFO
);
88 stui
.dwFlags
= STARTF_USESHOWWINDOW
;
89 stui
.wShowWindow
= SW_SHOWDEFAULT
;
91 if (CreateProcess (NULL
, szFullCmdLine
, NULL
, NULL
, FALSE
,
92 0, NULL
, NULL
, &stui
, &prci
))
97 WaitForSingleObject (prci
.hProcess
, INFINITE
);
98 GetExitCodeProcess (prci
.hProcess
, &dwExitCode
);
99 nErrorLevel
= (INT
)dwExitCode
;
100 CloseHandle (prci
.hThread
);
101 CloseHandle (prci
.hProcess
);
106 ErrorMessage (GetLastError (),
107 "Error executing CreateProcess()!!\n");