On Aug 30, 3:50*am, Hal Rottenberg <h...@xxxxxx> wrote:
Quote:
> bsdz wrote: Quote:
> > I need to pipe the output from a powershell commandlet to a perl
> > process. In its simplest form when I try: -
> Quote:
> > PS> 1..3 | perl -ne 'print "#$_#\n"'
>
> The short answer is that it doesn't work quite that way. *The pipeline is meant
> for use with cmdlets and Perl.exe doesn't speak that language. Not to worry, the
> syntax required is only slightly different and requires the foreach-object cmdlet.
>
> 1..3 | foreach-object { perl -ne 'print "#$_#\n"' }
>
> Just be careful with your quotes and escape characters, those may be a challenge
> with Perl especially as it shares a lot of those with PowerShell. *I'm afraid
> the $_ above won't be expanded as the larger string is within single quotes.
> Good luck with that. *
*You can always do double-double-quotes or escape them
> with the backtick and so on.
>
> --
> Author, Tech Prosaic blog (http://halr9000.com)
> Webmaster, Psi (http://psi-im.org)
> Community Director, PowerShellCommunity.org
> Co-host, PowerScripting Podcast (http://powerscripting.net) Thanks for your suggestion. Unfortunately, I cannot use it since it
invokes a new instance of Perl on each and every line piped through by
powershell. The main drivers for using Perl is it's superior
performance in string handling and although I boiled down my problem
to a simple example with 3 lines; my real problem entails processing
millions of lines - that's ~1h for powershell and ~5m for Perl.
I suspect I could write my own cmdlet that keeps a non-Powershell
process open and sends the powershell pipe stream to this process.
Actually, do you know of any such CmdLet?