I need to read only 1 char (number, to be exact) from cmd.exe. It must be done in only one keystroke. Is that possible? Not only cmd.exe, but I mean all standard utilities in windows (supported by WinXP-Win7).

PS set /p val=request is not what I looking for. It reads string, not only 1 char and require enter key. I need something what works like OnKeyDown: read 1 char and continue script execution, no enter needed.

  • I'm not positive how to answer this. Perhaps some more explaination on why you need this will help? – EBGreen Jun 28 '11 at 17:55
  • Are you reading from the keyboard or from another program's output? – user1686 Jun 28 '11 at 20:39

Not only cmd.exe, but I mean all standard utilities in windows (supported by WinXP-Win7).

Why would it need to be possible for, say, edlin.exe? That's a nonsensical requirement.

If you want to prompt for a single character, returning immediately once one is entered, then you are going to have to use some form of extra utility over and above what comes in the box with Windows NT 5.1, even if it's simply a Win32 clone of the MS-DOS 6.2 choice.com program (which, being an MS-DOS program, won't work on x86-64 Windows, of course).

With JP Software's TCC/LE, which is a replacement command interpreter, the built-in INKEY command does exactly what you ask for and can be used thusly:

inkey %%key

The key pressed is then in the key environment variable.

Alternatively, in the Windows NT 4.0 Server Resource Kit and later, Microsoft provides choice.exe, which is a Win32 clone of the MS-DOS choice.com. Note, however, that this is the Server Resource Kit. With Windows NT Server 5.2 and later, choice.exe is bundled in with Windows itself. However, again, note that this is the Server edition of Windows.

  • I found choice.exe in my Win7x64: C:\Windows\winsxs\x86_microsoft-windows-choice_31bf3856ad364e35_6.1.7600.16385_none_c33d412fed16819c It works great. – SmartiesForTheWin Jun 30 '11 at 17:58
  • choice is located in C:\Windows\System32\choice.exe in 64-bit Windows – phuclv Jun 24 '18 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.