windowscmd

Pasting commands after `timeout` doesn't execute them in cmd


I see the following bizarre behavior:

I paste this code in cmd:

echo test1
timeout 2
echo test2

I see the following output after 2 seconds:

C:\>echo test1
test1

C:\>timeout 2

Waiting for 0 seconds, press a key to continue ...

C:\>

Why isn't echo test2 executed?


Solution

  • timeout likely clears any input before waiting for "a key to continue". Note that echo test2 isn't printed as well. It works fine in a batch file.

    Note what happens when I paste this:

    set /p xyz=input? 
    echo test2
    

    Output:

    C:\>set /p xyz=input?
    input? echo test2
    
    C:\>set xyz
    xyz=echo test2
    

    The second "command" becomes input to set and sets the xyz variable.