I can confirm this issue as well. I think the problem is that when 'continue'
is called within gci (because the 'loop' is probably to be found somewhere in
there), the Cmdlet does not handle this situation correctly. I did a quickt
test on this and it seems that continue is supposed to act between different
steps of the pipeline (and sometimes even works as expected!):
0,1,2,3,4,5 | .{process{$_;continue}}
0
$(for($i=0;$i -lt 5;$i++){$i}) | .{process{$_;continue}}
0
$(foreach ($i in (0,1,2,3,4,5)) {$i}) | .{process{$_;continue}}
0
Get-Process | .{process{$_;continue}}
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
36 2 844 352 28 0,06 3168 ApntEx
gci c:\ | .{process{$_;continue}}
Directory: Microsoft.PowerShell.Core\FileSystem::C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 07.01.2006 13:37 ####
Get-ChildItem : Systemfehler
At line:1 char:4
+ gci <<<< c:\ | .{process{$_;continue}}
Note that the error message comes from Get-ChildItem in your example!
--
greetings
dreeschkind
"Roman Kuzmin" wrote:
> Replaying to <klumsy@gmail.com> I said that it would be perhaps more natural
> if 'continue' fails when looping is not found.
>
> But it does not fail in the examples Test1.ps1 and Test2.ps1.
>
> But it does fail in the example below and with very misleading message:
>
> CODE:
>
> gci c:\ | .{process{ $_; continue }}
>
> OUTPUT:
>
> Directory: Microsoft.PowerShell.Core\FileSystem::C:\
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> d---- 23/04/2006 22:53 xxx
> Get-ChildItem : System error.
> At line:1 char:4
> + gci <<<< c:\ | .{process{ $_; continue }}
>
> Note the error message and where an error is designated. In the real code it
> was not so easy to find that 'continue' caused an error.
>
> So,
> *) why does 'continue' fails here and does not in Test1.ps1 and Test2.ps1?
> *) what about this strange error message?
>
> --
> Thanks,
> Roman
>