[英]What does “$?” mean in PowerShell
I'm very new to PowerShell. 我是PowerShell的新手。 While looking up information about error handling I've found a lot of references to using "$?"
在查找有关错误处理的信息时,我发现了很多使用“ $?”的引用。
I know that it has something to do with errors but what exactly is it? 我知道这与错误有关,但究竟是什么呢? And where can I read more about it?
在哪里可以找到更多关于它的信息?
All of my Google searches have found nothing. 我所有的Google搜索都找不到任何内容。
From the The Essential Windows PowerShell Cheat Sheet : 从基本Windows PowerShell备忘单 :
Errors and Debugging: The success or failure status of the last command can be determined by checking $? 错误和调试:可以通过检查$?确定最后一个命令的成功或失败状态。
Example: 例:
> 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
Just after asking this I discovered the command "Get-Help -name about_automatic_variables" 在问了这个之后,我发现了命令“ Get-Help -name about_automatic_variables”
This gives information about every automatic variable in powershell, it's very helpful 这提供了有关Powershell中每个自动变量的信息,这非常有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.