graff has asked for the wisdom of the Perl Monks concerning the following question:

I normally work in unix, but this dual-boot laptop has WinXP, and sometimes I use that. So I installed the GNU cdrom of Windows ports, which works fine -- including the bash shell, which I use instead of "command.com", always. I also installed ActiveState Perl 5.8.2, and that seems to work also (bash handles perl scripts as executables nicely). But there's this little problem with using pipe commands to feed a perl script -- here's a demonstration:
bash$ ls junk test.junk bash$ ls | sed 's/\./-.-/' # piping between GNU utils works junk test-.-junk bash$ ls > junk bash$ perl -pe 's/\./-.-/' junk # perl reading from a file works junk test-.-junk bash$ perl -pe 's/\./-.-/' < junk # redirecting stdin from file works junk test-.-junk bash$ ls | perl -pe 's/\./-.-/' # using a pipeline # nothing comes out # trying the pipe again, more carefully this time: bash$ ls | perl -e 'while (<>) { > s/\./-.-/; > print; > } > print "all done\n";' all done
When I step through that last example with "perl -de", it never enters the while loop -- the first attempt to read input with the diamond operator fails (or yields the equivalent of EOF), and execution goes directly to the last line.

Any clues or hints about what's going wrong here? What am I missing?

Replies are listed 'Best First'.
Re: Read from a pipe with WinXP/AS 5.8.2?
by BrowserUk (Patriarch) on Jan 07, 2004 at 04:56 UTC

    You'll need to consult the docs/forums for the bash shell you are using

    P:\test>ls | perl -nle"s/\./-.-/; print" 237671-.-pl8 242776-.-pl8 243366-.-pl8 250383-.-pl8 250495-.-pl8 251580-.-pl8 251933-.-pl8 252633-.-pl8 253059-.-pl8 [snip]

    That's the GNU ls running under cmd.exe piping to AS perl5.8.1 under NT4.

    Update: It also works fine under the sh.exe that comes from GNU utilities for Win32.

    D:\WINNT\unxtools>sh HIAWATHA# ls | perl -ple" s/\./-.-/" FlexLexer-.-h StdDisclaimer-.-html UnxUtilsDist-.-html agrep-.-exe ansi2knr-.-exe basename-.-exe bc-.-exe bison-.-exe bison-.-hairy [snip]

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

      I see that cmd.exe is included with XP -- slight relief (command.com was all I knew, and it's such a pain), but this is still no substitute for bash. Oh well, at least I have a couple places to start looking (including Cygwin).

      Thanks to both of you!

      Update: following the Gnu link provided by BrowserUK above, I also happened to find yet another source of unix-environment tools for windows: http://www.research.att.com/sw/tools/uwin/ -- where the offerings include ksh (like bash, sort of, but a little different), which does what I want: pipes work as expected. It can also do real unix-style handling of the shebang line in perl scripts, and there appears to be an X-Windows component to the overall package -- gotta check that out... Altogether a very slick looking setup, though apparently not open-source.

Re: Read from a pipe with WinXP/AS 5.8.2?
by ysth (Canon) on Jan 07, 2004 at 04:53 UTC
    Is there any Windows specific documentation included with this GNU cdrom you are using? What happens if you try it under a cmd.exe prompt instead?

    Have you considered using cygwin instead?