Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press any key to continue [duplicate]

Tags:

powershell

According to Microsoft's documentation, read-host lets the user type some input, and then press enter to continue. Not exactly the correct behavior if you want to have "Press any key to continue". (Wait... where's the Any key?!)

Is there a way to accomplish this? Something like read-char?

I've tried searching for "single character input" and "powershell input" to see if I could find a list of all ways to get input without much luck. And several Stack Overflow questions that looked hopeful use read-host which doesn't actually work for "press any key..." functionality.

like image 730
Jeff B Avatar asked Jan 02 '14 15:01

Jeff B


People also ask

How to make press any key to continue in PowerShell?

Use cmd /c 'pause' Command to Enable the press any key to continue in the PowerShell. The cmd /c pause command displays the Press any key to continue . . . and pauses the execution until a key is pressed.


1 Answers

Here is what I use.

Write-Host -NoNewLine 'Press any key to continue...'; $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); 
like image 156
Knuckle-Dragger Avatar answered Sep 20 '22 19:09

Knuckle-Dragger