LoginSignup
5
8

More than 5 years have passed since last update.

PowerShellでPause

Posted at

なんかいつの間にか最新のWindows10までに入ってるみたいなんだけど,定義が以下のようになっている.

defaultPause.ps1
# > (Get-Command Pause).Definition
$null = Read-Host '続行するには、Enter キーを押してください...'

これだと任意のキーでよかったcmdのpauseとは勝手が違うし,そもそもいつまでだか分からないけど前はなかったので,使ってるのを貼ってみる.

Pause.ps1
function Pause
{
    if ($psISE) {
        $null = Read-Host 'Press Enter Key...'
    }
    else {
        Write-Host "Press Any Key..."
        (Get-Host).UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
    }
}

RawUI.ReadKey()も,[System.Console]::ReadKey()もISEでは使えないので,仕方なくRead-Hostにする.
それ以外は見ての通りで入力を待ってnullに投げるだけ.$nullに入れてもOut-Nullにパイプしても多分同じ.
この内容を$profileとかで呼んでやればfunction Pauseがなければ作られてあれば上書きされる.

5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8