Windows 7 Input redirection does not work with DOS commands

MtheK

New Member
I was trying to get the 'CD' (change directory) DOS command to work with
input redirection (left arrow), but could not do so, tho, thank goodness,
I found PUSHD&POPD so I no longer need CD in my .BAT now. However, I could not
get any of these commands to work either: TYPE, MORE, and especially DIR, as follows:

### used CD to set directory, then did DIR w/o any operands, produced this:
C:\DAD\temp\16bit>dir
Directory of C:\DAD\temp\16bit
05/17/2013 07:41 AM <DIR> .
05/17/2013 07:41 AM <DIR> ..
...
3 File(s) 799,445 bytes
2 Dir(s) 257,805,111,296 bytes free

### here is the contents of the file used for input redirection:
C:\DAD\temp\16bit>type c:\dad\temp\redirin.txt
\dad\temp\32bit

### using input redirection, DIR does NOT(!!??) show the DIR asked of it:
C:\DAD\temp\16bit>dir <\dad\temp\redirin.txt
/OR/
C:\DAD\temp\16bit>dir <\DAD\temp\REDIRIN.txt
/OR/
C:\DAD\temp\16bit>dir <C:\DAD\temp\REDIRIN.txt
Directory of C:\DAD\temp\16bit
05/17/2013 07:41 AM <DIR> .
05/17/2013 07:41 AM <DIR> ..
...
3 File(s) 799,445 bytes
2 Dir(s) 257,805,111,296 bytes free

### however, typing in the file contents manually WITHOUT input redirection works properly:
C:\DAD\temp\16bit>dir \dad\temp\32bit
/OR/
C:\DAD\temp\16bit>dir\dad\temp\32bit
Directory of C:\dad\temp\32bit
05/19/2013 07:28 AM <DIR> .
05/19/2013 07:28 AM <DIR> ..
...
6 File(s) 1,145,711 bytes
2 Dir(s) 257,805,111,296 bytes free

So I played around w/this in my own MASM program using the Win32 API. What I found was,
when I tried to use PEEKCONSOLEINPUT on the redirected STDIN handle, I get rc=6
(ERROR_INVALID_HANDLE), yet if I read it anyway using READFILE, it works properly;
I just pass a numeric 7 in the input redirection file to my program, which my
program sees properly per WinDbg and its' results (I use that value x1000 in SLEEP).

If no input redirection exists, PEEKCONSOLEINPUT works, but returns 0 records, which
is my indicator to NOT issue a READFILE so as NOT to lock up the console waiting for
keyboard input.

I tried opening a handle for CONIN$ under input redirection, and although it worked,
PEEK also said there were 0 records, so this was even WORSE; at least the rc=6 tells me
to ASSUME input redirection exists. I did not attempt to try to read it anyway,
in spite of it saying there was nothing to read, unlike when I got the rc=6 yet
there WAS something to read.

So: although I got input redirection to work in my program, tho flakey, is this
technique correct? And why can't I get DIR, CD, etc to work with input redirection?
Both of my laptops have Win7; 1 with SP1, 1 without and both fail as described above.
If there is a KB fix#, please post it here...
 
Regarding my program, now I base my decision on the result of GETFILETYPE,
which makes more sense; if FILE_TYPE_DISK, I do the READFILE, otherwise
I do the PEEK and trust the # of records returned. In my testing, now the
RC=6 can't occur, and all works as expected.

This, of course, does NOT explain why DIR, CD, etc won't work for me...
 
Back
Top