Hacking I/O Redirection Bug

As anyone who has used a command line since Unix was invented knows, you can redirect standard input and output by appending a "< inputfile" or "> outputfile" to the command line. Many people also know that on Windows, if you type to name of a file at a command prompt, and that file isn't […]

As anyone who has used a command line since Unix was invented knows, you can redirect standard input and output by appending a "< inputfile" or "> outputfile" to the command line.

Many people also know that on Windows, if you type to name of a file at a command prompt, and that file isn't an executable program, the system will launch the program that owns that kind of file and ask it to open the file. This is particularly handy for script files like Perl, where opening the file really means running the script. So you can run a Perl script just by typing "foo.pl".

Unfortunately, there's a bug that prevents these two very useful techniques from being used together. If you type "foo.pl >outputfile", your script bombs the first time it tries to write any output, and the output file ends up empty. This problem has been reported many times but has never been fixed, primarily because of fear of app compat (application compatibility) issues.

Full Article