PowerShell:清空哈希似乎不起作用:(

时间:2014-06-01 09:23:00

标签: powershell hash

我将从套接字(由于错误)获得的1行字符串转换为哈希:

     #the server-response: 
     $r = "8=FIX.4.4°9=77°35=0°34=98°49=COUNTERPARTY°52=20140531-22:45:04.752°56=FIXPUSHER°112=Testing°10=055"
     #convert to a hash:
     $hash = ConvertFrom-StringData -StringData ($r).Replace("°","`n")
     # let's try again..
     $hash.Clear() # or $hash = @{}
     $r = "8=FIX.4.4°9=77°35=0°34=98°49=COUNTERPARTY°52=20140531-22:45:04.752°56=FIXPUSHER°112=Testing°10=055"
     $hash = ConvertFrom-StringData -StringData ($r).Replace("°","`n")

(嗯?我必须找到一种重复错误的方法..)

现在我换了s.​​th.在我的程序中再次发送我的请求到服务器,我得到部分相同的行,特别是哈希的大多数键将返回。所以我试图清空那个哈希 - 但是没有任何东西真的有效:

     $hash = @{}

,也不

     $hash.Clear()

我总是得到错误(我的德语错误文本的英文翻译):
elemet" 8"在线" 8 = FIX.4.4"已定义...
所有的沟通都从这部分开始。

如何重新使用我的$ hash-variable来分析服务器的响应?

请知道吗? 提前谢谢,
Gooly

我可以给你更多信息。 错误发生在更大的循环中。如果我的脚本在调试模式下通过comd运行cmd,那么第一次(没有错误)只会滑过:

      $hash = ConvertFrom-StringData -StringData ($r).Replace("°","`n")

第二次时间($ hash已被清空)同一行跳转到ConvertFrom-StringData,产生此错误文本:

    [DBG]>>> Stoped at: if ($_.FullyQualifiedErrorId -ne "NativeCommandErrorMessage" -and $ErrorView -ne "CategoryView") {
    [DBG]>>> Stoped at: $myinv = $_.InvocationInfo
    [DBG]>>> Stoped at: switch -regex ( & { Set-StrictMode -Version 1; $myinv.MyCommand.CommandType } )
    [DBG]>>> Stoped at: switch -regex ( & { Set-StrictMode -Version 1; $myinv.MyCommand.CommandType } )
    [DBG]>>> Stoped at: switch -regex ( & { Set-StrictMode -Version 1; $myinv.MyCommand.CommandType } )
    [DBG]>>> Stoped at: if ( & { Set-StrictMode -Version 1; $myinv.MyCommand.Name } )
    [DBG]>>> Stoped at: if ( & { Set-StrictMode -Version 1; $myinv.MyCommand.Name } )
    [DBG]>>> Stoped at: if ( & { Set-StrictMode -Version 1; $myinv.MyCommand.Name } )
    [DBG]>>> Stoped at: $myinv.MyCommand.Name + " : "; break;
    [DBG]>>> Stoped at: $myinv.MyCommand.Name + " : "; break;
    [DBG]>>> Stoped at: if ($_.FullyQualifiedErrorId -eq "NativeCommandErrorMessage") {
    [DBG]>>> Stoped at: if ($_.InvocationInfo) {
    [DBG]>>> Stoped at: $posmsg = $_.InvocationInfo.PositionMessage
    [DBG]>>> Stoped at: if ( & { Set-StrictMode -Version 1; $_.PSMessageDetails } ) {
    [DBG]>>> Stoped at: if ( & { Set-StrictMode -Version 1; $_.PSMessageDetails } ) {
    [DBG]>>> Stoped at: if ( & { Set-StrictMode -Version 1; $_.PSMessageDetails } ) {
    [DBG]>>> Stoped at: & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
    [DBG]>>> Stoped at: & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
    [DBG]>>> Stoped at: & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
    [DBG]>>> Stoped at: $indent = 4
    [DBG]>>> Stoped at: $width = $host.UI.RawUI.BufferSize.Width - $indent - 2
    [DBG]>>> Stoped at: $indentString = "+ CategoryInfo          : " + $_.CategoryInfo
    [DBG]>>> Stoped at: $posmsg += "`n"
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: $indentString = "+ FullyQualifiedErrorId : " + $_.FullyQualifiedErrorId
    [DBG]>>> Stoped at: $posmsg += "`n"
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: foreach($line in @($indentString -split "(.{$width})")) { if($line) { $posmsg += (" " * $indent + $line) } }
    [DBG]>>> Stoped at: if ($ErrorView -eq "CategoryView") {
    [DBG]>>> Stoped at: elseif (! $_.ErrorDetails -or ! $_.ErrorDetails.Message) {
    [DBG]>>> Stoped at: $_.Exception.Message + $posmsg + "`n "
    ConvertFrom-StringData : The element "8" in line "8=FIX.4.4" has been already defined. 
    At C:\Users\cas\Documents\sysTools\PC\WindowsPowerShell\Socke_005.ps1:194 Char:35
    +     $hash = ConvertFrom-StringData <<<<  -StringData ($msgRcv).Replace($I,"`n")
      + CategoryInfo          : InvalidOperation: (:) [ConvertFrom-StringData], PSInvalidOperationException
      + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand

(我的英文翻译)有什么想法吗?

0 个答案:

没有答案