Brian Rasmussen Brian Rasmussen - 1 year ago 75
Perl Question

Perl on Windows, file associations and I/O redirection

Can someone explain the difference between calling a perl script via file association versus calling the same script explicitly via


Apparently I/O redirection doesn't work very well when the script is called via file association, and I would really like to know why.

E.g. take a look at the Activestate FAQ for Perl on Windows. The
cat file
example works perfectly as long as the script doesn't receive its input via redirection. So

cat file.txt

works as expected, but

whoami |

does not. Not only is the
extension needed, but apparently the output of
isn't piped into the script. The script is run (which can be verified by modifying the example
script), but for some reason it doesn't receive the output of
as input.

However, if I call the script like this:

whoami | perl

everything works as expected.

So apparently there is an important difference between running the script via file association and explicitly calling
with the script.

The FAQ mentions the problem and points out that using
to generate a bat file cover for the script fixes the problem, but I don't understand why this is necessary.

Please enlighten me.

Answer Source

It looks like it was a known bug in Windows 2000: STDIN/STDOUT Redirection May Not Work If Started from a File Association.

I get the same behaviour you describe with Strawberry Perl on WinXP, however once I created the registry entry described in the above article (even though the reg entry is targetted at Win2K), stdin works as expected.

Edit: I ought to add that even though the KB article claims it was fixed in XP SP1, I've got XP SP3 installed. So whether MS have broken this, or never fixed it completely, I can't say!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download