mercredi 28 septembre 2016

input and output of cmd command

I have next script test.bat:

@ECHO OFF

echo output inVal = %inVal%
SET /p inVal="input "
echo output inVal = %inVal%

dir  >NUL 2>&1
if %errorlevel% == 1 (
    echo non existing dir
) else (
    echo existing dir
    SET /p inVal="input "
    echo output inVal = %inVal%
)

And the output after my inputs is:

> test.bat
output inVal = 5
input 7
output inVal = 7
existing dir
input 3
output inVal = 7
>
> test.bat
output inVal = 3
input 8
output inVal = 8
existing dir
input 2
output inVal = 8
>

first question: on the second run, the output starts with number 3, that should be the last output from the first run, but for some reason it is not. Why?

second question: in second run, the last output should be 2, instead, it is 8: "output inVal = 8" Why?

Aucun commentaire:

Enregistrer un commentaire