2016-03-19 8 views
2

、型変換など例:トレース/デバッグPowerShellのオペレーター

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 
... 

私は-lt比較がどのように機能するかを追跡したかったPSでいくつかの奇妙なbehaviousをデバッグしている間(多分それ各文字などのために[int][char]"x"に変換されます)。 Trace-Commandを使用しようとしましたが、何も返されません。

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を例として使用しましたが、これは同様にコマンドやその他のものを解析する方法と同様に可能です。

+0

私も同様の問題があります。 DynamicObject、IEnumerableを継承し、TryBinaryOperationをオーバーライドする独自のクラスを実装しました。しかし、PS比較演算子はTryBinaryOperatorメソッドを私の型の一番左のオペランドではなく、右のオペランドが文字列でGetEnumeratorが呼び出された場合に呼びます。私はAST PSが私のカスタムタイプのために適切に実装するために比較演算子のために何を構築するのかを理解する必要があります。 –

答えて

1

-lt-gtは大文字と小文字を区別しない演算子で、-iltと-igtのように動作します。大文字と小文字を区別する演算子が必要な場合は-clt-cgtを使用してください。ここで

は、私はそれが私が-cgtを使用する場合、私は同じトレースを得るが、結果はTrueある

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 

を助けわからないI'am、PowerShellの5.0で得られた結果です。

+0

Huh ..私はPS 5.0を実行している3つの異なるコンピュータでそれを試しましたが、何も返されませんでした。クリーンインストールの時期だと思います。これはちょっと質問に答えますが、私は少し深くなることを望んでいました。 Ex。どのようなクラス、メソッドなどが呼び出されたかを知ることができるように、コールスタックまたはオペレータのための何かを得ることができます。たぶんそれは可能ではないかもしれませんが、私はあなたのような人々の知識に驚いているので、誰かが魔法の解決策を持っているかどうかもう少し分かります。 :-)ありがとう –

+0

Windows PowerShell v5.1/PowerShell Core v6.0-alpha.17では、上記のコマンドはトレース出力をまったく生成しません。また、たとえば、Windows PowerShell v5.0.10586.117で得られるこの回答のトレース出力には、スクリプトブロック内の特定の式に関する情報が含まれていないため、 '{}'を渡すと非常に同じトレース出力が得られます。すなわち、_empty_スクリプトブロック。 – mklement0