Link to home
Start Free TrialLog in
Avatar of Sybux
SybuxFlag for Switzerland

asked on

text menu with default option and timeout in a shell script

Hi,

I'd like to write a little shell script which ask the user to chooce between n choice and I want that the program go on after 30 seconds for example if the user didn't choose anything.

in batch cmd I was using the choice command but as it is for beeing run under windows PE 3.0 dos command are very poor.

Thx in advance
Avatar of Justin Mathews
Justin Mathews

If JScript is supported you can copy the following script into a file choice.js and run from command line as CScript choice.js:

WScript.Echo ("Select an option:");
WScript.Echo ("\t1. Option 1");
WScript.Echo ("\t2. Option 2");
WScript.Echo ("\t3. Option 3");
WScript.Echo ("\t4. Option 4");
WScript.Echo ("\t5. Option 5");

var tm = new Date().getTime();

var input = "";
while (!(input = WScript.StdIn.Read(1)).match(/[1-5]/) && (new Date().getTime() - tm) < 30*1000);

WScript.Echo(input);

Here is a site with a workaround for the "missing" choice command in Windows PE:  http://www.msfn.org/board/topic/117000-pe-20-batch-menu/

Since it sounds like you may already have the script working using choice in another version of Windows you should be able to easily modify what you have using the code on the site.
Avatar of Sybux

ASKER

it's nearly working except that the wscript.stdin is blocking the execution of the script as it's waiting for an input
It will wait max of 30 sec or until user types in 1-5 and ENTER.
Avatar of Sybux

ASKER

no, it wait until I press a key. I'm surprise as you.
Avatar of Sybux

ASKER

I can't choice is a 16bits application and can't run under winPE (only 32bits)
ASKER CERTIFIED SOLUTION
Avatar of Steven Carnahan
Steven Carnahan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial