Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Piped input read by Windows Vista but not by Windows XP

by roho (Abbot)
on Nov 01, 2010 at 19:52 UTC ( #868871=perlquestion: print w/replies, xml ) Need Help??
roho has asked for the wisdom of the Perl Monks concerning the following question:

I have AS Perl 5.8.9 (build 827) on Windows Vista and Windows XP. Piped input is read by the Perl program on Vista but is not read by the same Perl program on XP, even though Perl programs can be run implicitly on both Vista and XP by just entering the program name on the command line.

Following is the command line I am using and the Perl program I am piping input to. This is a simplified example to show the difference between how Vista and XP handle piped input. I am grepping all lines of a file (the test program in this case, but it could be any file) with the '-n' option to precede each line with a line number and colon. The output of grep is piped to the Perl program where the colon following the line number is removed and the line is printed.

Note: I found that if I use '... | perl' instead of '... |' on XP it will read the piped input, but I do not believe I should have to do that to make it work. Does anyone have any ideas why piped input is not read on XP? Thanks.

grep -n "^" | #!/usr/bin/perl # Perl program use strict; use warnings; while ( <> ) { chomp; s/:/ /; print "$_\n"; }

"Its not how hard you work, its how much you get done."

Replies are listed 'Best First'.
Re: Piped input read by Windows Vista but not by Windows XP
by kcott (Canon) on Nov 01, 2010 at 23:29 UTC

    While I can't give you an answer as to why, I can confirm this behaviour. I first tried your code on cygwin: pipe worked fine. Then tried with XP (using same code and running from the same directory): got the same as you. Furthermore, taking the input from stdin rather than pipe worked fine.

    Here's my tests:

    ken@Miranda ~/c/_/tmp $ cat > #!perl use strict; use warnings; while (<>) { chomp; s/:/ /; print "$_\n"; } ken@Miranda ~/c/_/tmp $ echo 'fred:derf' fred:derf ken@Miranda ~/c/_/tmp $ chmod +x ken@Miranda ~/c/_/tmp $ echo 'fred:derf' | fred derf ken@Miranda ~/c/_/tmp $ Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\_\tmp>echo 'fred:derf' 'fred:derf' C:\_\tmp>echo 'fred:derf' | C:\_\tmp>echo 'fred:derf' | perl 'fred derf' C:\_\tmp> fred:derf fred derf C:\_\tmp>

    -- Ken

Re: Piped input read by Windows Vista but not by Windows XP
by Anonymous Monk on Nov 02, 2010 at 00:12 UTC
      Thanks for the explanation. It makes sense now. Too bad M$ never got around to fixing this in XP.

      "Its not how hard you work, its how much you get done."

        It has been fixed in most cases for a long time. See Re: Out of date over <> and 5.10 (redir) for more about it. Still, nobody has been able to demonstrate what causes only some instances to exhibit this problem.

        - tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://868871]
Approved by lostjimmy
[erix]: the neighbours (a nat.hist. museum) have a narwhal skull with *2* tusks
[erix]: ( also: UniCorn Throne )
[zentara]: erix I hope both tusks pointed in the same direction :-)
LanX "♪..♫ Last night a DJ killed my wife ♪..♫ "
zentara...oO 1 more reason I prefer Perl to Python is I can't believe how long Python takes to compile, and you can't disable the myriad of tests
[LanX]: so that's where you've been the last two years? Compiling Python?
[zentara]: LanX no! I was learning why Krishna made me into a unicorn. :-)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2017-03-30 16:43 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (361 votes). Check out past polls.