1

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.

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

1 Answer 1

1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .