Friday, June 29, 2012

[CMD.EXE] Console weirdness

What do you make of a command line tool that stops working and seems to wait for keyboard input, but the code doesn't have a keyboard input instruction anywhere in it? I just had a batch file (that calls two PHP files and an EXE) sit idle for 2 hours and then start working as soon as I hit a key in its window.

After digging around a bit for a solution, where should I find it but at PerlMonks:

If your cmd.exe windows have "Quick edit" mode enabled, then if you (or somebody) left-clicks in the window (say to bring it to the top of the window stack), then it can select (highlight for copy & paste), one or more characters. A side effect of this is that output to the screen is suspended until the C&P is completed by right-clicking.

And if the program is regularly outputting to the screen, then undisplayed output will accumulate until the internal buffer fills, at which point the next write attempt will block until the select state is ended. Effectively suspending the program. The select state can be ended by right-clicking in the window so completing the copy & paste operation.

It can also be ended by typing any key, which abandons the C&P and allow the blocked write to succeed and the program to continue. Ie. Exactly the symptoms you've described.

The Quick-edit mode is very useful, but it can be confusing if you are not aware of it, or its affects.
        -- Re^3: Perl suddenly pauses for key input
Weird ... can it get any weirder than this?
© Copyright Bruce M. Axtens, 2012

No comments: