cmd.exe: Add 2>&1 and 1>&2 support.

This commit is contained in:
Jason Edmeades 2007-03-13 00:10:38 +00:00 committed by Alexandre Julliard
parent 4ef2f8ba1a
commit a801995cdb
1 changed files with 29 additions and 10 deletions

View File

@ -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);
}