powershell - Waiting for user input with a timeout -


i have searched apparently google foo weak. need way prompt user input in console , have request time out after period of time , continue executing script if no input comes in. near can tell, read-host not provide functionality. neither $host.ui.promptforchoice() nor $host.ui.rawui.readkey(). in advance pointers.

edit: lars truijens finding answer. have taken code pointed out , encapsulated function. note way have implemented means there 1 second of delay between when user hits key , when script execution continues.

function pause-host {     param(             $delay = 1          )     $counter = 0;     while(!$host.ui.rawui.keyavailable -and ($counter++ -lt $delay))     {         [threading.thread]::sleep(1000)     } } 

found here:

$counter = 0 while(!$host.ui.rawui.keyavailable -and ($counter++ -lt 600)) {       [threading.thread]::sleep( 1000 ) } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -