From b49405229649a8a353846905595de5a30cade29e Mon Sep 17 00:00:00 2001 From: Brandon Turner Date: Fri, 16 Sep 2005 04:40:46 +0000 Subject: [PATCH] Use compsec instead of "cmd" when trying to find cmd.exe svn path=/trunk/; revision=17872 --- reactos/subsys/system/cmd/start.c | 50 +++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/reactos/subsys/system/cmd/start.c b/reactos/subsys/system/cmd/start.c index c1b676da8f8..7b6e958a5a7 100644 --- a/reactos/subsys/system/cmd/start.c +++ b/reactos/subsys/system/cmd/start.c @@ -23,6 +23,8 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) TCHAR first[CMDLINE_LENGTH]; TCHAR *rest = NULL; TCHAR *param = NULL; + INT size; + LPTSTR comspec; BOOL bWait = FALSE; BOOL bBat = FALSE; BOOL bCreate = FALSE; @@ -38,14 +40,41 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) return 0; } + /* get comspec */ + comspec = malloc ( MAX_PATH * sizeof(TCHAR)); + if (comspec == NULL) + { + error_out_of_memory(); + return 1; + } + SetLastError(0); + size = GetEnvironmentVariable (_T("COMSPEC"), comspec, 512); + if(GetLastError() == ERROR_ENVVAR_NOT_FOUND) + { + Rest = _T("cmd"); + } + else + { + if (size > MAX_PATH) + { + comspec = realloc(comspec,size * sizeof(TCHAR) ); + if (comspec==NULL) + { + return 1; + } + size = GetEnvironmentVariable (_T("COMSPEC"), comspec, size); + } + } + nErrorLevel = 0; if( !*Rest ) { - // FIXME: use comspec instead - Rest = _T("cmd"); + _tcscpy(Rest,_T("\"")); + _tcscat(Rest,comspec); + _tcscat(Rest,_T("\"")); } - + rest = malloc ( _tcslen(Rest) + 1 * sizeof(TCHAR)); if (rest == NULL) { @@ -158,19 +187,8 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) bBat = TRUE; memset(szFullCmdLine,0,CMDLINE_LENGTH * sizeof(TCHAR)); - /* FIXME : use comspec instead */ - if (!SearchForExecutable (_T("CMD"), szFullCmdLine)) - { - error_bad_command (); - if (rest != NULL) - free(rest); - - if (param != NULL) - free(param); - - return 1; - } + _tcscpy(szFullCmdLine,comspec); memcpy(&szFullCmdLine[_tcslen(szFullCmdLine)],_T("\" /K \""), 6 * sizeof(TCHAR)); memcpy(&szFullCmdLine[_tcslen(szFullCmdLine)], szFullName, _tcslen(szFullName) * sizeof(TCHAR)); @@ -217,7 +235,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) { bCreate = CreateProcess (szFullName, szFullCmdLine, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &stui, &prci); - + } if (bCreate)