Author: hbelusca
Date: Mon Jul 1 00:07:39 2013
New Revision: 59405
URL:
http://svn.reactos.org/svn/reactos?rev=59405&view=rev
Log:
[CMD]
Fix the default input & output console modes. Now, you can use the command interpreter
via serial port redirection, by:
1- Enabling a serial port on the machine on which ReactOS runs.
2- Launching:
cmd > AUX
at a command prompt.
Modified:
trunk/reactos/base/shell/cmd/cmd.c
trunk/reactos/base/shell/cmd/redir.c
Modified: trunk/reactos/base/shell/cmd/cmd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=5…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Mon Jul 1 00:07:39 2013
@@ -414,21 +414,20 @@
stui.dwFlags = STARTF_USESHOWWINDOW;
stui.wShowWindow = SW_SHOWDEFAULT;
- // return console to standard mode
+ /* Set the console to standard mode */
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),
- ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT);
-
- if (CreateProcess (szFullName,
- szFullCmdLine,
- NULL,
- NULL,
- TRUE,
- 0, /* CREATE_NEW_PROCESS_GROUP */
- NULL,
- NULL,
- &stui,
- &prci))
-
+ ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
+
+ if (CreateProcess(szFullName,
+ szFullCmdLine,
+ NULL,
+ NULL,
+ TRUE,
+ 0, /* CREATE_NEW_PROCESS_GROUP */
+ NULL,
+ NULL,
+ &stui,
+ &prci))
{
CloseHandle(prci.hThread);
}
@@ -449,32 +448,33 @@
EnterCriticalSection(&ChildProcessRunningLock);
dwChildProcessId = prci.dwProcessId;
- WaitForSingleObject (prci.hProcess, INFINITE);
+ WaitForSingleObject(prci.hProcess, INFINITE);
LeaveCriticalSection(&ChildProcessRunningLock);
- GetExitCodeProcess (prci.hProcess, &dwExitCode);
+ GetExitCodeProcess(prci.hProcess, &dwExitCode);
nErrorLevel = (INT)dwExitCode;
}
- CloseHandle (prci.hProcess);
+ CloseHandle(prci.hProcess);
}
else
{
TRACE ("[ShellExecute failed!: %s]\n", debugstr_aw(Full));
- error_bad_command (first);
+ error_bad_command(first);
dwExitCode = 1;
}
- // restore console mode
- SetConsoleMode (
- GetStdHandle( STD_INPUT_HANDLE ),
- ENABLE_PROCESSED_INPUT );
- }
-
- /* Get code page if it has been change */
+ /* Restore our default console mode */
+ SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),
+ ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
+ SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),
+ ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
+ }
+
+ /* Get code page if it has been changed */
InputCodePage= GetConsoleCP();
OutputCodePage = GetConsoleOutputCP();
- SetConsoleTitle (szWindowTitle);
+ SetConsoleTitle(szWindowTitle);
return dwExitCode;
}
@@ -1360,7 +1360,7 @@
*/
BOOL
-ReadLine (TCHAR *commandline, BOOL bMore)
+ReadLine(TCHAR *commandline, BOOL bMore)
{
TCHAR readline[CMDLINE_LENGTH];
LPTSTR ip;
@@ -1426,7 +1426,7 @@
/*
* control-break handler.
*/
-BOOL WINAPI BreakHandler (DWORD dwCtrlType)
+BOOL WINAPI BreakHandler(DWORD dwCtrlType)
{
DWORD dwWritten;
INPUT_RECORD rec;
@@ -1637,18 +1637,18 @@
NtReadVirtualMemoryPtr = (NtReadVirtualMemoryProc)GetProcAddress(NtDllModule,
"NtReadVirtualMemory");
}
- InitLocale ();
+ InitLocale();
/* get default input and output console handles */
- hOut = GetStdHandle (STD_OUTPUT_HANDLE);
- hIn = GetStdHandle (STD_INPUT_HANDLE);
+ hOut = GetStdHandle(STD_OUTPUT_HANDLE);
+ hIn = GetStdHandle(STD_INPUT_HANDLE);
/* Set EnvironmentVariable PROMPT if it does not exists any env value.
for you can change the EnvirommentVariable for prompt before cmd start
this patch are not 100% right, if it does not exists a PROMPT value cmd should
use
$P$G as defualt not set EnvirommentVariable PROMPT to $P$G if it does not exists
*/
if (GetEnvironmentVariable(_T("PROMPT"),lpBuffer, sizeof(lpBuffer) /
sizeof(lpBuffer[0])) == 0)
- SetEnvironmentVariable (_T("PROMPT"), _T("$P$G"));
+ SetEnvironmentVariable(_T("PROMPT"), _T("$P$G"));
#ifdef FEATURE_DIR_STACK
/* initialize directory stack */
@@ -1667,10 +1667,13 @@
SetEnvironmentVariable (_T("COMSPEC"), ModuleName);
}
- /* add ctrl break handler */
- AddBreakHandler ();
-
- SetConsoleMode (hIn, ENABLE_PROCESSED_INPUT);
+ /* Add ctrl break handler */
+ AddBreakHandler();
+
+ /* Set our default console mode */
+ SetConsoleMode(hOut, 0); // Reinitialize the console output mode
+ SetConsoleMode(hOut, ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
+ SetConsoleMode(hIn , ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
ENABLE_ECHO_INPUT);
cmdLine = GetCommandLine();
TRACE ("[command args: %s]\n", debugstr_aw(cmdLine));
@@ -1800,10 +1803,15 @@
/* free GetEnvVar's buffer */
GetEnvVar(NULL);
- /* remove ctrl break handler */
- RemoveBreakHandler ();
- SetConsoleMode(GetStdHandle( STD_INPUT_HANDLE ),
- ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT);
+ /* Remove ctrl break handler */
+ RemoveBreakHandler();
+
+ /* Restore the default console mode */
+ SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),
+ ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
+ SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),
+ ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
+
DeleteCriticalSection(&ChildProcessRunningLock);
}
Modified: trunk/reactos/base/shell/cmd/redir.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/redir.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/redir.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/redir.c [iso-8859-1] Mon Jul 1 00:07:39 2013
@@ -61,8 +61,7 @@
static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
/* Some parameters used for read, write, and append, respectively */
- static
- struct REDIR_PARAMS
+ static struct REDIR_PARAMS
{
DWORD dwDesiredAccess;
DWORD dwShareMode;