Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Perl thinks it's the shell!

by misterw (Acolyte)
on Jun 02, 2005 at 04:21 UTC ( #462743=perlquestion: print w/replies, xml ) Need Help??

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

Running on XP I type:
at the console prompt and get the following
Can't exec /c/apps/pp3.exe at line 1. looks like this:
#!/c/apps/pp3.exe print "Hello\n";
The shebang notation is there for cygwin. pp3.exe is a c program that translates cygwin paths to windows paths before calling the real perl interpreter. So that if I run the script from bash like this:
$ /c/some/path/orother
then the right path (using windows path separators) gets through to the (activestate) perl interpreter
Which is all good, except (back to the original problem) why is perl.exe even looking at this line? As far as it's concerned it's a comment, right?

I've tried:

and also double clicking in explorer and perl.exe seems to want to evaluate the shebang notation.

I'm sure this is not the normal perl for windows (or any platform) behaviour???

...More testing...
In fact if I set the shebang to another c program such as args.exe then it runs that instead of the perl interpreter even though perl calls the script directly

I have a bad feeling I'm missing something here...


Perl is:

perl -v This is perl, v5.8.6 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 811 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Dec 13 2004 09:52:01

20050502 Edit by ysth: change pre to code tags

Replies are listed 'Best First'.
Re: Perl thinks it's the shell!
by ikegami (Pope) on Jun 02, 2005 at 04:27 UTC

    From perlrun,

    If the #! line does not contain the word ``perl'', the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #!, because they can tell a program that their SHELL is /usr/bin/perl, and Perl will then dispatch the program to the correct interpreter for them.

    Also, I believe Apache uses the #! line rather the file association.

    On a related note, (again from perlrun)

    The #! line is always examined for switches as the line is being parsed. Thus, if you're on a machine that allows only one argument with the #! line, or worse, doesn't even recognize the #! line, you still can get consistent switch behavior regardless of how Perl was invoked, even if -x was used to find the beginning of the program.

    so -w and other switches on the #! line will work in Windows, even though Windows doesn't know about the #! line.

      Thanks so much. I thought I was going NUTS!

      In correction to my original post (since updated) it does work with callperl.exe but originally it was

      and that didn't work , which added to my confusion(I should have noticed this when posting). Seeing this, I then actually started adding and deleting letters from the shebang line and got what seemed to be random results.
      !#/c/apps/callperl.exe and !#/c/apps/callperllllll.exe
      worked but

      I didn't happen to think that it might be to do with the word perl

      Thanks again for the quick response, You get good service here!!!

      This is the second time I have come across mysterious (yes, should have read the docs) perl (related - though not perls fault) problems on windows. At first callperl.exe kept stealing spaces from my command line arguments until I realised that you need to double quote all command line parameters containing spaces. This is important for system and exec in c which call CreateProcess on windows platforms.


        Fellow misterw
        This is a classical. :-) Just do like the emacs users do:

        #!/c/apps/pp3.exe # -*- perl -*-

        This solves your problem, I guess. This solved my problems, when I was dealing with this kind'o'stuff.

        May the gods bless your work.

      Verging on OT, but:

      Also, I believe Apache uses the #! line rather the file association.
      Correct. When I used Windows, I always installed ActivePerl to c:/usr/ instead of the standard c:/Perl/, this way the standard shebang (#!/usr/bin/perl) worked without any conversions, assuming of course that Apache also was on C:

        What I do is install Activestate Perl in the default spot then create the directory path C:\usr\bin\ into which I drag-drop a copy of perl.exe. Apache uses this executable as detailed in the shebang #!/usr/bin/perl . Since the executable knows where its libs are, everything works like a charm. You can then take your locally-developed scripts and port them to *nix platforms if you want with nary an edit!

        (Ph) Phaysis (Shawn)
        If idle hands are the tools of the devil, are idol tools the hands of god?

Re: Perl thinks it's the shell!
by Anonymous Monk on Jun 02, 2005 at 07:09 UTC
    the shell? Maybe a shell :)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://462743]
Approved by BrowserUk
Front-paged by ikegami
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-09-24 07:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found