MS-DOS input redirection does work after call of attrib command

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I am trying to write a interactive DOS scrip that asks the user to answer
some question (using SET /P command). When I provide the answers in a text
file using the input (stdin) redirection, the input redirection seems to be
broken after a call of attrib command. Does any body encounter this problem?

My test case is simple.
I use the following script:
prompt >type testsilent.cmd
@echo off
set A=n
set B=n
set C=n
set D=n
set /P A="A="
echo.
set /P B="B="
echo.
attrib +R file.txt
set /P C="C="
echo.
set /P D="D="
echo.
echo A=%A%
echo B=%B%
echo C=%C%
echo D=%D%

The answer file is:
prompt >type answers.txt
y
y
y
y

Here the file.txt could be any file.
If I run this scrip using the following command:
prompt>testsilent.cmd < answers.txt
the result is :
A=
B=
C=
D=
A=y
B=y
C=n
D=n

Where we expect
A=
B=
C=
D=
A=y
B=y
C=y
D=y

If I comment the attrib call, the result is the one we expected.

Does any body know about this issue, if it is a known problem and if there
is any fix?
Thanks
Adnene BEN ABDALLAH
 
Looks like the problem is that the attrib command can also accept such
inputs (although how it uses them, if at all, is a mystery)

Change the "attrib +R file.txt" line to something like
attrib +R file.txt <file2.txt (where file2.txt is blank)
and it should work ok


Jon
 
How should your batch file know how to apply
the piped input data? You expect that it knows by
sheer magic that the input is meant for the set /p
commands. This is not the case: attrib.exe will
swallow some or all of your input too! Replace
attrib.exe with some other command and you will
get a similar effect.

You must have your set /p commands in one
contiguous block if you want them to work as
expected.
 
Thank you for your answer.
I have an additional question. Do you know if there is in windows an
equivalent of /dev/null in UNIX, so I can redirect internal calls input to it?

Thanks
Adnene
 
Back
Top