Module: wine Branch: master Commit: a801995cdbe4976785762e431b9d0648696ff46a URL: http://source.winehq.org/git/wine.git/?a=commit;h=a801995cdbe4976785762e431b...
Author: Jason Edmeades us@edmeades.me.uk Date: Tue Mar 13 00:10:38 2007 +0000
cmd.exe: Add 2>&1 and 1>&2 support.
---
programs/cmd/wcmdmain.c | 39 +++++++++++++++++++++++++++++---------- 1 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 037efcc..1bb9154 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -533,18 +533,37 @@ void WCMD_process_command (char *command) else { creationDisposition = CREATE_ALWAYS; } + + /* Add support for 2>&1 */ redir = p; - h = CreateFile (WCMD_parameter (p, 0, NULL), GENERIC_WRITE, 0, &sa, creationDisposition, - FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) { - WCMD_print_error (); - HeapFree( GetProcessHeap(), 0, cmd ); - return; - } - if (SetFilePointer (h, 0, NULL, FILE_END) == - INVALID_SET_FILE_POINTER) { - WCMD_print_error (); + if (*p == '&') { + int idx = *(p+1) - '0'; + + if (DuplicateHandle(GetCurrentProcess(), + GetStdHandle(idx_stdhandles[idx]), + GetCurrentProcess(), + &h, + 0, TRUE, DUPLICATE_SAME_ACCESS) == 0) { + WINE_FIXME("Duplicating handle failed with gle %d\n", GetLastError()); + } + WINE_TRACE("Redirect %d (%p) to %d (%p)\n", handle, GetStdHandle(idx_stdhandles[idx]), idx, h); + + } else { + char *param = WCMD_parameter (p, 0, NULL); + h = CreateFile (param, GENERIC_WRITE, 0, &sa, creationDisposition, + FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + WCMD_print_error (); + HeapFree( GetProcessHeap(), 0, cmd ); + return; + } + if (SetFilePointer (h, 0, NULL, FILE_END) == + INVALID_SET_FILE_POINTER) { + WCMD_print_error (); + } + WINE_TRACE("Redirect %d to '%s' (%p)\n", handle, param, h); } + old_stdhandles[handle] = GetStdHandle (idx_stdhandles[handle]); SetStdHandle (idx_stdhandles[handle], h); }