首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跟踪/调试PowerShell操作符

跟踪/调试PowerShell操作符
EN

Stack Overflow用户
提问于 2016-03-19 07:37:32
回答 1查看 361关注 0票数 2

在PowerShell中,我可以使用Trace-Command解决参数绑定、类型转换等问题,例如:

代码语言:javascript
复制
Trace-Command -PSHost -Name ParameterBinding -Expression { $null = "c:\" | dir}
...
DEBUG: ParameterBinding Information: 0 :     Parameter [Path] PIPELINE INPUT ValueFromPipeline NO COERCION
DEBUG: ParameterBinding Information: 0 :     BIND arg [c:\] to parameter [Path]
DEBUG: ParameterBinding Information: 0 :         Binding collection parameter Path: argument type [String], parameter type [System.String[]], collection type Array, eleme
nt type [System.String], no coerceElementType
...

在调试PS中的一些奇怪行为时,我想跟踪-lt比较是如何工作的(也许它会将每个字符转换为[int][char]"x",等等)。我试着使用Trace-Command,但是它没有返回任何东西。

代码语言:javascript
复制
Trace-Command -PSHost -Name TypeMatch, TypeConversion -Expression { "Less" -lt "less" }
#No trace-output, only returned value
False

#Get any type of trace-informatino
Trace-Command -PSHost -Name * -Expression { "Less" -lt "less" }
#No trace-output, only returned value
False

有没有办法找出这些内部操作人员是如何在幕后工作的?追踪信息?详细的输出?--我使用了-lt-gt作为示例,但这也可以是&-operator以及它如何解析命令或其他东西。

EN

回答 1

Stack Overflow用户

发布于 2016-03-19 22:54:47

不确定这是否有帮助,但-lt-gt是不区分大小写的操作符,它们的行为类似于-ilt和-igt。如果需要区分大小写的运算符,则应使用-clt-cgt

这是我在PowerShell 5.0中获得的结果,我不确定它是否有帮助

代码语言:javascript
复制
Trace-Command -PSHost -Name TypeMatch, TypeConversion -Expression { "Less" -lt "less" }
DÉBOGUER : TypeConversion Information: 0 : Converting "System.Object[]" to "System.Object".
DÉBOGUER : TypeConversion Information: 0 :     Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "" to "System.String".
DÉBOGUER : TypeConversion Information: 0 :     Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "" to "System.String".
DÉBOGUER : TypeConversion Information: 0 :     Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "System.Management.Automation.InvocationInfo" to "System.Management.Automation.InvocationInfo".
DÉBOGUER : TypeConversion Information: 0 :     Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "System.Object[]" to "System.Object[]".
DÉBOGUER : TypeConversion Information: 0 :     Result type is assignable from value to convert's type
False

如果使用-cgt,我将获得相同的跟踪,但结果是True

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36099167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档