Sch*_*ler 4 variables error-handling powershell powershell-2.0
我是PowerShell的新手.在查找有关错误处理的信息时,我发现了许多使用"$?"的参考资料.
我知道它与错误有关但究竟是什么呢?我在哪里可以阅读更多相关信息?
我的所有Google搜索都没有找到任何结果.
错误和调试:最后一个命令的成功或失败状态可以通过检查$来确定?
例:
> Get-Content file-that-exists.txt
Hello world
> Write-Host $?
True
> Get-Content file-that-does-not-exist.txt
Get-Content : Cannot find path 'C:\file-that-does-not-exist.txt' because it does not exist.
At line:1 char:1
+ Get-Content file-that-does-not-exist.txt
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\file-that-does-not-exist.txt:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
> Write-Host $?
False
Run Code Online (Sandbox Code Playgroud)
就在问完这个问题后,我发现了命令“Get-Help -name about_automatic_variables”
这提供了有关 powershell 中每个自动变量的信息,非常有帮助
| 归档时间: |
|
| 查看次数: |
2882 次 |
| 最近记录: |