http://qs321.pair.com?node_id=147234

If your a perl programmer on Windows and find yourself running perl programs from the CLI (Command Line Interface) and get annoyed by having to run perl foo.pl all the time, then this is for you.

You don't have to do this if your running Windows NT 4/5 (2000) because theres a way round it. There are two little programs called assoc and ftype. These programs allow tou to associate the .pl extension or any other extension you use with the perl interpretor. so when you want to run a program called foo.pl you can just type foo at the CLI, as long as its in your CWD (Current Working Directory) or your PATH.

All you will need to do is follow these steps.

1) Open up a CLI. and enter these commands:
C:\> assoc .pl=PerlScript
C:\> ftype PerlScript=C:\Path\To\Perl\bin\perl.exe %1 %*

2) While still in the CLI type this:
C:\> set PATHEXT=.pl;%PATHEXT%

The PATHEXT environment variable contains the extension(s) to executables. So by adding .pl to this anything (files) found with the .pl extension will be treated as executable. This will only last for your CLI session, so if you want to make this a permanent thing do the following:

1) Right click on 'My Computer' and select properties. 2) Move along to the Advanced tab. 3) Click on Environment Variables. 4) In the System Variables double click on PATHEXT. 5) Append a ';.pl' to the end or a '.pl;' to the beggining of the Vari +able value box. 6) Click on all of the OK's and Apply's, restart your CLI and try it o +ut.

Edit kudra, 2002-02-26 Added 'NT' to title per ntc request

Edit by tye to change PRE to CODE when around long lines.

Replies are listed 'Best First'.
Re: Win32 Execution: UNiX Style
by osfameron (Hermit) on Feb 25, 2002 at 11:40 UTC
    Moving from typing <cite>perl foo.pl</cite> to <cite>foo</cite> using the above method will work for standalone programs but not for more complicated Command Lines, e.g. <cite>foo > foo_results.txt</cite> Similarly, if foo.pl is a filter (like a pager program, or a program that makes substitutions to its input), then <cite>mycommand | foo</cite> also won't work.

    This is due to a bug, apparently in Win32. (Though as batch files and executables can quite happily redirect input/output, I don't understand why it can't be circumvented??).

    A workaround is to turn any perl scripts that need to redirect IO into a batch file, which doesn't have the same bug... Luckily the handy pl2bat program that comes standard with Win32 distributions of Perl does this, basically by putting a batch wrapper script around your Perl code.

    pl2bat foo.pl foo.bat | more foo | more foo > results.txt dir | foo
    Note: This doesn't contradict the effectiveness of the original technique above for simple scripts though!

    Cheerio!
    Osfameron
    http://osfameron.perlmonk.org/chickenman

      hi,

      ive got w2k/datacenter running and i can do stuff like redirect output, and it works with 'more'.

Re: Win32 Execution: UNiX Style
by clemburg (Curate) on Feb 25, 2002 at 11:41 UTC

    BTW, if you are still typing the complete filename all the time on WinNT systems, use this small registry patch file to make TAB the completion character on the WinNT commandline.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Re: Win32 Execution: UNiX Style (NT)
by gjb (Vicar) on Oct 25, 2002 at 15:24 UTC

    I can wholeheartedly recommend cygwin, a bash shell that runs under WinWhatever and comes with most tools you expect on a UNIX (gcc, gdb, UNIX file utils, etc). At the time of writing, even Perl 5.8.0 can be installed.

    Since gcc is part of the deal, a lot of UNIX software can be compiled and run under Windows.

    Currently it has a nice installer that can be found on the cygwin site and that allows to install software components as needed.

    It makes live a lot more bearable on a Windows box.

    Hope this helps, -gjb-

A reply falls below the community's threshold of quality. You may see it by logging in.