Author: jmorlan Date: Sun Mar 29 23:17:45 2009 New Revision: 40289
URL: http://svn.reactos.org/svn/reactos?rev=40289&view=rev Log: Make cmd able to (sort of) work without a console.
Modified: trunk/reactos/base/shell/cmd/cmd.c trunk/reactos/base/shell/cmd/cmd.h trunk/reactos/base/shell/cmd/cmdinput.c trunk/reactos/base/shell/cmd/console.c
Modified: trunk/reactos/base/shell/cmd/cmd.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=40... ============================================================================== --- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Sun Mar 29 23:17:45 2009 @@ -164,7 +164,6 @@ OSVERSIONINFO osvi; HANDLE hIn; HANDLE hOut; -HANDLE hConsole; LPTSTR lpOriginalEnvironment; HANDLE CMD_ModuleHandle;
@@ -1380,7 +1379,12 @@ } }
- ReadCommand (readline, CMDLINE_LENGTH - 1); + if (!ReadCommand(readline, CMDLINE_LENGTH - 1)) + { + bExit = TRUE; + return FALSE; + } + if (CheckCtrlBreak(BREAK_INPUT)) { ConOutPuts(_T("\n")); @@ -1805,6 +1809,7 @@ */ int cmd_main (int argc, const TCHAR *argv[]) { + HANDLE hConsole; TCHAR startPath[MAX_PATH]; CONSOLE_SCREEN_BUFFER_INFO Info; INT nExitCode; @@ -1821,12 +1826,16 @@ hConsole = CreateFile(_T("CONOUT$"), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - if (GetConsoleScreenBufferInfo(hConsole, &Info) == FALSE) - { - ConErrFormatMessage(GetLastError()); - return(1); - } - wDefColor = Info.wAttributes; + if (hConsole != INVALID_HANDLE_VALUE) + { + if (!GetConsoleScreenBufferInfo(hConsole, &Info)) + { + ConErrFormatMessage(GetLastError()); + return(1); + } + wDefColor = Info.wAttributes; + CloseHandle(hConsole); + }
InputCodePage= GetConsoleCP(); OutputCodePage = GetConsoleOutputCP();
Modified: trunk/reactos/base/shell/cmd/cmd.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=40... ============================================================================== --- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Sun Mar 29 23:17:45 2009 @@ -53,7 +53,6 @@ /* global variables */ extern HANDLE hOut; extern HANDLE hIn; -extern HANDLE hConsole; extern LPTSTR lpOriginalEnvironment; extern WORD wColor; extern WORD wDefColor; @@ -120,7 +119,7 @@
/* Prototypes for CMDINPUT.C */ -VOID ReadCommand (LPTSTR, INT); +BOOL ReadCommand (LPTSTR, INT);
/* Prototypes for CMDTABLE.C */
Modified: trunk/reactos/base/shell/cmd/cmdinput.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmdinput.c?r... ============================================================================== --- trunk/reactos/base/shell/cmd/cmdinput.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmdinput.c [iso-8859-1] Sun Mar 29 23:17:45 2009 @@ -126,8 +126,9 @@
/* read in a command line */ -VOID ReadCommand (LPTSTR str, INT maxlen) +BOOL ReadCommand (LPTSTR str, INT maxlen) { + CONSOLE_SCREEN_BUFFER_INFO csbi; SHORT orgx; /* origin x/y */ SHORT orgy; SHORT curx; /*current x/y cursor position*/ @@ -149,11 +150,30 @@ TCHAR PreviousChar; #endif
+ if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) + { + /* No console */ + HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); + DWORD dwRead; + CHAR chr; + do + { + if (!ReadFile(hStdin, &chr, 1, &dwRead, NULL) || !dwRead) + return FALSE; +#ifdef _UNICODE + MultiByteToWideChar(InputCodePage, 0, &chr, 1, &str[charcount++], 1); +#endif + } while (chr != '\n' && charcount < maxlen); + str[charcount] = _T('\0'); + return TRUE; + } + /* get screen size */ - GetScreenSize (&maxx, &maxy); - - GetCursorXY (&orgx, &orgy); - GetCursorXY (&curx, &cury); + maxx = csbi.dwSize.X; + maxy = csbi.dwSize.Y; + + curx = orgx = csbi.dwCursorPosition.X; + cury = orgy = csbi.dwCursorPosition.Y;
memset (str, 0, maxlen * sizeof (TCHAR));
@@ -590,4 +610,5 @@ /* expand all aliases */ ExpandAlias (str, maxlen); #endif /* FEATURE_ALIAS */ + return TRUE; }
Modified: trunk/reactos/base/shell/cmd/console.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/console.c?re... ============================================================================== --- trunk/reactos/base/shell/cmd/console.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/console.c [iso-8859-1] Sun Mar 29 23:17:45 2009 @@ -413,7 +413,7 @@ { CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo (hConsole, &csbi); + GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
*x = csbi.dwCursorPosition.X; *y = csbi.dwCursorPosition.Y; @@ -424,7 +424,7 @@ { CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo (hConsole, &csbi); + GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
return csbi.dwCursorPosition.X; } @@ -434,7 +434,7 @@ { CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo (hConsole, &csbi); + GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
return csbi.dwCursorPosition.Y; } @@ -444,7 +444,11 @@ { CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo (hConsole, &csbi); + if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) + { + csbi.dwSize.X = 80; + csbi.dwSize.Y = 25; + }
if (maxx) *maxx = csbi.dwSize.X;
Hi!
2009/3/29 jmorlan@svn.reactos.org:
Author: jmorlan Date: Sun Mar 29 23:17:45 2009 New Revision: 40289
URL: http://svn.reactos.org/svn/reactos?rev=40289&view=rev Log: Make cmd able to (sort of) work without a console.
Thanks! I am now able to run telnetd and connect in to my ReactOS VM. Certain applications such as ctm don't seem to like running without a console due to making calls to GetConsoleMode. I am going to test telnetd on Windows with Windows cmd.exe and ReactOS cmd.exe to compare behavior of these applications. Its possible cmd.exe returns some bogus console mode or something when running without a console.
Thanks