mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
Corrected CreateProcess() command line parameter to be more compatible with NT
Fixed minor bugs with console mode being set incorrectly svn path=/trunk/; revision=1982
This commit is contained in:
parent
35b12b3d8c
commit
045f617089
2 changed files with 34 additions and 29 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: cmd.c,v 1.26 2001/05/06 17:12:44 cnettel Exp $
|
/* $Id: cmd.c,v 1.27 2001/06/18 02:55:47 phreak Exp $
|
||||||
*
|
*
|
||||||
* CMD.C - command-line interface.
|
* CMD.C - command-line interface.
|
||||||
*
|
*
|
||||||
|
@ -226,21 +226,17 @@ Execute (LPTSTR first, LPTSTR rest)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* exec the program */
|
/* exec the program */
|
||||||
#ifndef __REACTOS__
|
|
||||||
TCHAR szFullCmdLine [CMDLINE_LENGTH];
|
TCHAR szFullCmdLine [CMDLINE_LENGTH];
|
||||||
#endif
|
|
||||||
PROCESS_INFORMATION prci;
|
PROCESS_INFORMATION prci;
|
||||||
STARTUPINFO stui;
|
STARTUPINFO stui;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
DebugPrintf ("[EXEC: %s %s]\n", szFullName, rest);
|
DebugPrintf ("[EXEC: %s %s]\n", szFullName, rest);
|
||||||
#endif
|
#endif
|
||||||
#ifndef __REACTOS__
|
|
||||||
/* build command line for CreateProcess() */
|
/* build command line for CreateProcess() */
|
||||||
_tcscpy (szFullCmdLine, szFullName);
|
_tcscpy (szFullCmdLine, first);
|
||||||
_tcscat (szFullCmdLine, _T(" "));
|
_tcscat (szFullCmdLine, _T(" "));
|
||||||
_tcscat (szFullCmdLine, rest);
|
_tcscat (szFullCmdLine, rest);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* fill startup info */
|
/* fill startup info */
|
||||||
memset (&stui, 0, sizeof (STARTUPINFO));
|
memset (&stui, 0, sizeof (STARTUPINFO));
|
||||||
|
@ -248,8 +244,11 @@ Execute (LPTSTR first, LPTSTR rest)
|
||||||
stui.dwFlags = STARTF_USESHOWWINDOW;
|
stui.dwFlags = STARTF_USESHOWWINDOW;
|
||||||
stui.wShowWindow = SW_SHOWDEFAULT;
|
stui.wShowWindow = SW_SHOWDEFAULT;
|
||||||
|
|
||||||
#ifndef __REACTOS__
|
// return console to standard mode
|
||||||
if (CreateProcess (NULL,
|
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
|
||||||
|
ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
|
||||||
|
|
||||||
|
if (CreateProcess (szFullName,
|
||||||
szFullCmdLine,
|
szFullCmdLine,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -259,18 +258,6 @@ Execute (LPTSTR first, LPTSTR rest)
|
||||||
NULL,
|
NULL,
|
||||||
&stui,
|
&stui,
|
||||||
&prci))
|
&prci))
|
||||||
#else
|
|
||||||
if (CreateProcess (szFullName,
|
|
||||||
rest,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
FALSE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&stui,
|
|
||||||
&prci))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
/* FIXME: Protect this with critical section */
|
/* FIXME: Protect this with critical section */
|
||||||
bChildProcessRunning = TRUE;
|
bChildProcessRunning = TRUE;
|
||||||
|
@ -291,6 +278,9 @@ Execute (LPTSTR first, LPTSTR rest)
|
||||||
ErrorMessage (GetLastError (),
|
ErrorMessage (GetLastError (),
|
||||||
"Error executing CreateProcess()!!\n");
|
"Error executing CreateProcess()!!\n");
|
||||||
}
|
}
|
||||||
|
// restore console mode
|
||||||
|
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
|
||||||
|
ENABLE_PROCESSED_INPUT );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __REACTOS__
|
#ifndef __REACTOS__
|
||||||
|
@ -942,7 +932,6 @@ Initialize (int argc, char *argv[])
|
||||||
hOut = GetStdHandle (STD_OUTPUT_HANDLE);
|
hOut = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||||
hIn = GetStdHandle (STD_INPUT_HANDLE);
|
hIn = GetStdHandle (STD_INPUT_HANDLE);
|
||||||
|
|
||||||
SetConsoleMode (hIn, ENABLE_PROCESSED_INPUT);
|
|
||||||
|
|
||||||
if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2))
|
if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2))
|
||||||
{
|
{
|
||||||
|
@ -957,6 +946,7 @@ Initialize (int argc, char *argv[])
|
||||||
" /T:bf Sets the background/foreground color (see COLOR command)."));
|
" /T:bf Sets the background/foreground color (see COLOR command)."));
|
||||||
ExitProcess (0);
|
ExitProcess (0);
|
||||||
}
|
}
|
||||||
|
SetConsoleMode (hIn, ENABLE_PROCESSED_INPUT);
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_CHDIR
|
#ifdef INCLUDE_CMD_CHDIR
|
||||||
InitLastPath ();
|
InitLastPath ();
|
||||||
|
@ -1140,6 +1130,8 @@ static VOID Cleanup (int argc, char *argv[])
|
||||||
|
|
||||||
/* remove ctrl break handler */
|
/* remove ctrl break handler */
|
||||||
RemoveBreakHandler ();
|
RemoveBreakHandler ();
|
||||||
|
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
|
||||||
|
ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ INT cmd_start (LPTSTR first, LPTSTR rest)
|
||||||
{
|
{
|
||||||
TCHAR szFullName[MAX_PATH];
|
TCHAR szFullName[MAX_PATH];
|
||||||
BOOL bWait = FALSE;
|
BOOL bWait = FALSE;
|
||||||
|
TCHAR *param;
|
||||||
|
|
||||||
if (_tcsncmp (rest, _T("/?"), 2) == 0)
|
if (_tcsncmp (rest, _T("/?"), 2) == 0)
|
||||||
{
|
{
|
||||||
|
@ -49,15 +50,24 @@ INT cmd_start (LPTSTR first, LPTSTR rest)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if( !*rest )
|
||||||
|
{
|
||||||
|
// FIXME: use comspec instead
|
||||||
|
rest = "cmd";
|
||||||
|
}
|
||||||
/* get the PATH environment variable and parse it */
|
/* get the PATH environment variable and parse it */
|
||||||
/* search the PATH environment variable for the binary */
|
/* search the PATH environment variable for the binary */
|
||||||
if (!SearchForExecutable (first, szFullName))
|
param = strchr( rest, ' ' ); // skip program name to reach parameters
|
||||||
|
if( param )
|
||||||
|
{
|
||||||
|
*param = 0;
|
||||||
|
param++;
|
||||||
|
}
|
||||||
|
if (!SearchForExecutable (rest, szFullName))
|
||||||
{
|
{
|
||||||
error_bad_command ();
|
error_bad_command ();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if this is a .BAT or .CMD file */
|
/* check if this is a .BAT or .CMD file */
|
||||||
if (!_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".bat")) ||
|
if (!_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".bat")) ||
|
||||||
!_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".cmd")))
|
!_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".cmd")))
|
||||||
|
@ -78,9 +88,12 @@ INT cmd_start (LPTSTR first, LPTSTR rest)
|
||||||
DebugPrintf ("[EXEC: %s %s]\n", szFullName, rest);
|
DebugPrintf ("[EXEC: %s %s]\n", szFullName, rest);
|
||||||
#endif
|
#endif
|
||||||
/* build command line for CreateProcess() */
|
/* build command line for CreateProcess() */
|
||||||
_tcscpy (szFullCmdLine, szFullName);
|
_tcscpy (szFullCmdLine, first);
|
||||||
_tcscat (szFullCmdLine, _T(" "));
|
if( param )
|
||||||
_tcscat (szFullCmdLine, rest);
|
{
|
||||||
|
_tcscat(szFullCmdLine, " " );
|
||||||
|
_tcscat (szFullCmdLine, param);
|
||||||
|
}
|
||||||
|
|
||||||
/* fill startup info */
|
/* fill startup info */
|
||||||
memset (&stui, 0, sizeof (STARTUPINFO));
|
memset (&stui, 0, sizeof (STARTUPINFO));
|
||||||
|
@ -88,8 +101,8 @@ INT cmd_start (LPTSTR first, LPTSTR rest)
|
||||||
stui.dwFlags = STARTF_USESHOWWINDOW;
|
stui.dwFlags = STARTF_USESHOWWINDOW;
|
||||||
stui.wShowWindow = SW_SHOWDEFAULT;
|
stui.wShowWindow = SW_SHOWDEFAULT;
|
||||||
|
|
||||||
if (CreateProcess (NULL, szFullCmdLine, NULL, NULL, FALSE,
|
if (CreateProcess (szFullName, szFullCmdLine, NULL, NULL, FALSE,
|
||||||
0, NULL, NULL, &stui, &prci))
|
CREATE_NEW_CONSOLE, NULL, NULL, &stui, &prci))
|
||||||
{
|
{
|
||||||
if (bWait)
|
if (bWait)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue