How do you do a ‘Pause’ with PowerShell 2.0?

前端 未结 5 792
一生所求
一生所求 2020-12-07 10:27

OK, I\'m losing it. PowerShell is annoying me. I\'d like a pause dialog to appear, and it won\'t.

PS W:\\>>> $host.UI.RawUI.ReadKey(\"NoEcho,Include         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-07 11:31

    The solutions like cmd /c pause cause a new command interpreter to start and run in the background. Although acceptable in some cases, this isn't really ideal.

    The solutions using Read-Host force the user to press Enter and are not really "any key".

    This solution will give you a true "press any key to continue" interface and will not start a new interpreter, which will essentially mimic the original pause command.

    Write-Host "Press any key to continue..."
    [void][System.Console]::ReadKey($true)
    

提交回复
热议问题