JojoLinkyBob has asked for the wisdom of the Perl Monks concerning the following question:

I've noticed that running a script in a WinNT shell without prepending the command with "perl " essentially disables STDOUT.
For example: If I have a script called foo.pl that prints out a list:

1) c:> foo.pl => generates no output

2) c:> perl foo.pl => generates output

Does this have anything to do with it being run as an association? I've heard that this problem doesn't occur on Win2K platforms...

Is there a way to run it so I don't have to type "perl " before it, and have it write out?
Thx,
Desert coder

Replies are listed 'Best First'.
Re: NT Bug w/ Perl?
by bikeNomad (Priest) on Jul 18, 2001 at 02:32 UTC
    I don't know about Win2K, but under Win95 and WinNT 4, this is in fact the case. File associations throw away their stdout, it seems. Make them into batch (.cmd) files and they work better. There is a perl2bat script that should allow you to package your scripts as .cmd files.

      And the pl2bat script's documentation makes for some interesting reading.

              - tye (but my friends call me "Tye")
Re: NT Bug w/ Perl?
by John M. Dlugosz (Monsignor) on Jul 18, 2001 at 02:51 UTC
    I've used it for years, never typing "perl" in front of the script name, and it works exactly as you would expect.

    How are you creating the association? I'm not familiar with how CMD.exe does it, but I think it pulls in registry associations (same as double-clicking on a GUI file list) if you use the /X command to create the shell window. So, check your association! You might be associating .pl with wperl, not perl, which is a GUI-mode version that indeed has no STDOUT (it doesn't force a console window to appear when you click on a .pl file in explorer that way).

    I've always used 4NT as my command shell, and that has an independant mechanism that existed long before they added it to CMD.EXE or COMMAND.COM. If you download that and try it, do a  SET .pl=blah/blah/blah/perl.exe on the command line, and then try it. Eventually you'll put that in autoexec.bat or somesuch place.

    —John

Re: NT Bug w/ Perl?
by larryk (Friar) on Jul 18, 2001 at 13:01 UTC
    I had a vaguely similar problem a while back where I would call a perl script with several arguments from the command line and if I called it as perl script.pl arg1 arg2 arg3 it was fine but if I did script.pl arg1 arg2 arg3, althought the script was invoked, @ARGV was empty. I figure it was a bug with that particular build but I don't have the build number nor did I check to see if their site mentioned anything about it.

    "Argument is futile - you will be ignorralated!"

Re: NT Bug w/ Perl?
by Hofmator (Curate) on Jul 18, 2001 at 15:44 UTC

    I just wanted to confirm that there are (= I've experienced :) no such problems with Win2K if you correctly associate .pl with perl.

    -- Hofmator

Re: NT Bug w/ Perl?
by rrwo (Friar) on Jul 19, 2001 at 01:49 UTC

    It isn't an issue on Windows 2000.

    It's a (frustrating) quirk with how Windows NT handles file associations. If STDOUT is important, just type Perl in front of it.

    Try looking at the .bat files that come with ActivePerl. There's a way to embed Perl in .bat's.