`Read-Host` should have a `-TimeoutSecond` parameter
See original GitHub issueSummary of the new feature / enhancement
If the user input isn’t strictly required and some default can be used, it may make sense to have Read-Host
have a timeout so that the script isn’t blocked indefinitely.
Proposed technical implementation details (optional)
Would need to show the timeout, default, and countdown.
Issue Analytics
- State:
- Created 4 months ago
- Reactions:2
- Comments:14 (3 by maintainers)
Top Results From Across the Web
How to configure a timeout for Read-Host in PowerShell
The idea seems to be to check whenever the user pressed a key using $Host.UI.RawUI.KeyAvailable and check that for the duration of your...
Read more >add 'TimeOut' and 'DefaultValue' parameter to read-host
Summary of the new feature / enhancement Pwsh has no timeout. ... Read-Host should have a -TimeoutSecond parameter #19664.
Read more >[SOLVED] Function in powertshell - PowerShell
I was thinking it would be good to have the following on a function and set the $value_input to 0 if the right...
Read more >PowerShell: Read-Host with Timeout - The Curious Geek
When I use the -join operator to turn the char array into a string, it processes the backspaces and the resultant string does...
Read more >Wait-Event (Microsoft.PowerShell.Utility)
The Wait-Event cmdlet suspends execution of a script or function until a particular event is raised. Execution resumes when the event is detected....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just to tie in a few conceptually related issues:
Unfortunately the Read-Host Cmdlet does not respond to the PowerShell being stopped.
Although Microsoft.PowerShell.PSConsoleReadLine does implement a ReadLine that takes a CancellationToken it doesn’t work until a key has been entered.
So even though the five seconds has elapsed, the ReadLine does not return until a key has been pressed.