redirect

Perl IO redirection problems on Windows

Question: 

On Unix I can run commands like "foo.pl | bar.pl" and have the output of foo.pl be the input of bar.pl. This doesn't seem to work on Windows. How can I make this work?

Answer: 

The Windows command interpreter cmd.exe does not support IO redirection for programs started via shell associations, like those created for .pl files during the ActivePerl installation. It only works for .bat, .com, .cmd, and .exe files.

You need to write:

perl foo.pl | perl bar.pl

Or if the files are not in your current directory but are on the PATH:

perl -S foo.pl | perl -S bar.pl

Alternatively, you can wrap your .pl files into .bat scripts using pl2bat:

pl2bat foo.pl
pl2bat bar.pl

Then run them as:

a | b

This is also the case for > and <.