Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

pipe to script requires '| perl' on win32

by QM (Parson)
on Apr 03, 2004 at 00:05 UTC ( #342192=perlquestion: print w/replies, xml ) Need Help??
QM has asked for the wisdom of the Perl Monks concerning the following question:

On win32, I have a problem with reading from a pipe on STDIN only (files on the command line work as expected). I have to call the script with perl, as below.

Update: I found this and perldoc pl2bat.

Here's the script:

print while <>;
With this command
echo "one two three" |
I get no output, but with this
echo "one two three" | perl
I get
"one two three"
Is this expected behavior? [Oddly enough, using pl2bat DWIM, but I was hoping to avoid that.]

assoc and ftype give...


c:\> assoc .pl .pl=Perl
c:\> ftype Perl Perl="C:\Perl\bin\perl.exe" "%1" %*

Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re: pipe to script requires '| perl' on win32
by tachyon (Chancellor) on Apr 03, 2004 at 00:28 UTC

    Is this expected behaviour?

    In the pl2bat docs which you even link to it is documented

    This is due to a Win32 bug which Perl has no control over. This bug i +s the major motivation for B<pl2bat> [which was originally written fo +r DOS] being used on Win32 systems.

    So it is documented behaviour. As for expected I would have to say yes. If you expect that Win32 will let you down in various ways you are unlikely to be disappointed ;-) Windows shell functionality is perhaps best described as a somewhat neglected development area. You could also get into rant mode and question why M$ had to 'fix' stuff that was not broken and leave stuff broken that needs fixing.

    The bottom line is that when you go to the shell, any shell, stuff that works in one shell will not work on another shell. That is after all why they are different shells ;-) It would work using Cygwin with a shebang.



Re: pipe to script requires '| perl' on win32
by inman (Curate) on Apr 03, 2004 at 17:29 UTC
    The Command prompt (cmd.exe) will pipe information from one 'process' to a 'thing' where the target is either an executable (.exe, .com) or a batch file (.bat, .cmd). The key is that the target must be supported directly by CMD.exe without external help.

    The command prompt will also 'do something' with any filename that you type in and press enter. The action carried out is the default action determined by the registry entries for the particular file extension. Normally this application is something that lets you view or edit the file. e.g. enter index.htm and IE loads the file.

    In the example above, the current directory contains a file called If you enter at the command prompt, the .pl extension is associated with Perl.exe and so the file will be sent to Perl.exe with as the first argument. Since the file happens to contain some instructions that Perl.exe can understand, Perl.exe carries out the instructions.

    This behavior kind of makes Perl scripts look like programs in their own right since the default action sends them to Perl.exe and they do something. Perl.exe does it's own thing in the background and we kind of forget that it is running. is however still just a file and not an executable. When you try and pipe the output from another program into the file then you don't get very far since you pipe into processes not files. If on the other hand you use the explicit Perl or PL2BAT route then you are piping into a process that has as it's first argument.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://342192]
Approved by kvale
[shmem]: welcome back, canary!

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2018-02-21 21:50 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (288 votes). Check out past polls.