#navi(../)
* PowerShellでexitの値を取得する方法・$lastexitcode [#c8a0b4e7]
PowerShellで書いたスクリプト内のexitの戻り値を取得するには、自動変数である$lastexitcodeを参照すると確認することができます。~
以下にサンプルスクリプトを記します。
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* 関連記事 [#be6c6e79]
-[[PowerShellスクリプトを起動できるようにする>PowerShell/PowerShellスクリプトを起動できるようにする]]
-[[PowerShellのバージョンを確認する方法>PowerShell/PowerShellのバージョンを確認する方法・$PSVersionTable]]
* $lastexitcodeを使う [#a4caaabc]
#ref(exit99.ps1)
サンプルスクリプトはexit 99のみを記述したものです。
exit 99
PowerShellを起動し、exit99.ps1を実行し$lastexitcodeを確認してみます。
PS C:\Users\sakura> .\exit99.ps1
PS C:\Users\sakura> $LASTEXITCODE
99
PS C:\Users\sakura> $lastexitcode
99
大文字、小文字のどちらでも確認することができます。
以上、PowerShellでスクリプトが返却するexitの値を取得する方法でした。
//#htmlinsertpcsp(win-btm.html,win-sp.html)