3テラバイト

プログラム関連備忘録サイト。主にゲーム。

PowerShell

PowerShellでプロセスの停止を待機するコマンドレットWait-Processの使い方

投稿日:

こんにちは、今日はPowerShellでプロセスの停止を待機するコマンドレットWait-Processの使い方についてまとめていきます。

確認環境

PSVersion 5.1.18362.1110

Wait-Processの使い方

停止するのを待ちたいプロセスをNameやIdで指定します。

以下の例ではメモ帳が終了するのを待ちます。

Wait-Process -Name "notepad"

指定したプロセスが無い場合は以下のようなエラーが表示されます。

PS C:\Users\santerabyte> Wait-Process -Name "notepad"
Wait-Process : 名前 "notepad" のプロセスが見つかりません。プロセス名を確認し、コマンドレットを再度呼び出してください。
発生場所 行:1 文字:1
+ Wait-Process -Name "notepad"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (notepad:String) [Wait-Process], ProcessCommandException
    + FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.WaitProcessCommand

リンク

Wait-Process (Microsoft.PowerShell.Management) – PowerShell | Microsoft Docs
https://docs.microsoft.com/ja-jp/powershell/module/microsoft.powershell.management/wait-process?view=powershell-5.1

-PowerShell


comment

メールアドレスが公開されることはありません。

関連記事

no image

PowerShellでアイテムのコンテンツを設定するコマンドレットSet-Contentの使い方

こんにちは、今日はPowerShellでアイテムのコンテンツを設定するコマンドレットSet-Contentの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 …

no image

PowerShellでコマンド一覧を取得するコマンドレットGet-Commandの使い方

こんにちは、今日はPowerShellでコマンド一覧を取得するコマンドレットGet-Commandの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 Get …

no image

PowerShellで関数を定義する方法

定義方法 引数なし 引数なしの関数は以下のように定義します。中かっこの中に任意の処理を記述します。 function Test-Func { Write-Host Hello World } 実行する …

no image

PowerShellで現在の日時を取得するコマンドレットGet-Dateの使い方

こんにちは、今日はPowerShellで現在の日時を取得するコマンドレットGet-Dateの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 Get-Dat …

no image

UnityでPowerShellの実行結果を取得する

以下の例ではGet-ChildItemコマンドレットを引数なしで実行、標準出力への出力をDebug.LogでUnityコンソールに出力しています。 System.Diagnostics.Process …