From 9e518dc79d914062628791b623a1691256374ff5 Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Sun, 4 Mar 2007 22:39:22 +0000 Subject: [PATCH] cmd.exe: Fix stdio redirects. --- programs/cmd/wcmdmain.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index bb805e6fcd9..1bea185a074 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -47,7 +47,6 @@ const char version_string[] = "CMD Version " PACKAGE_VERSION "\n\n"; const char anykey[] = "Press Return key to continue: "; char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH]; BATCH_CONTEXT *context = NULL; -static HANDLE old_stdin = INVALID_HANDLE_VALUE, old_stdout = INVALID_HANDLE_VALUE; extern struct env_stack *pushd_directories; static char *WCMD_expand_envvar(char *start); @@ -314,6 +313,8 @@ void WCMD_process_command (char *command) char *whichcmd; SECURITY_ATTRIBUTES sa; char *new_cmd; + HANDLE old_stdin = INVALID_HANDLE_VALUE; + HANDLE old_stdout = INVALID_HANDLE_VALUE; /* Move copy of the command onto the heap so it can be expanded */ new_cmd = HeapAlloc( GetProcessHeap(), 0, MAXSTRING ); @@ -587,12 +588,10 @@ void WCMD_process_command (char *command) if (old_stdin != INVALID_HANDLE_VALUE) { CloseHandle (GetStdHandle (STD_INPUT_HANDLE)); SetStdHandle (STD_INPUT_HANDLE, old_stdin); - old_stdin = INVALID_HANDLE_VALUE; } if (old_stdout != INVALID_HANDLE_VALUE) { CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE)); SetStdHandle (STD_OUTPUT_HANDLE, old_stdout); - old_stdout = INVALID_HANDLE_VALUE; } } @@ -606,8 +605,7 @@ static void init_msvcrt_io_block(STARTUPINFO* st) GetStartupInfo(&st_p); st->cbReserved2 = st_p.cbReserved2; st->lpReserved2 = st_p.lpReserved2; - if (st_p.cbReserved2 && st_p.lpReserved2 && - (old_stdin != INVALID_HANDLE_VALUE || old_stdout != INVALID_HANDLE_VALUE)) + if (st_p.cbReserved2 && st_p.lpReserved2) { /* Override the entries for fd 0,1,2 if we happened * to change those std handles (this depends on the way wcmd sets