http://qs1969.pair.com?node_id=167481

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

Okay, here's the idea (I don't know if this is possible but hey, what the heck):

I'm running Apache on Windows XP but my site is hosted on a machine running Linux. In order for my scripts to work on my XP box, my shebang line looks like:

#!c:/Perl/bin/perl

However, when I post my scripts to the host machine, the shebang line needs to be:

#!/usr/bin/perl

My question is: Is there a way to mimic/alias/redirect/*whatever* a *nix path to a user-defined Windows path? That way I could set up my machine to handle the *nix-based shebang line...sorta like:

"/usr/bin/perl = c:/Perl/bin/perl"

I'm getting tired of switching shebang lines around all the time in my scripts between here (my pc) and there (host pc).

TIA

======================
Sean Shrum
http://www.shrum.net

Replies are listed 'Best First'.
(wil) Re: How do I...Fool Windows into using *nix formatted shebang
by wil (Priest) on May 18, 2002 at 10:46 UTC
    You shouldn't have to do this anymore with Perl for Windows, as it automatically updates the Registry, so as long as you name your files with an appropriate extension - .pl or maybe .cgi then Windows should automatically detect these as Perl scripts and just treat your shebang line as a comment.

    Update: You might also have to uncomment the following line in your httpd.conf file to ensure that Apache looks up the correct location within the Windows Registry rather than refering to the shebang line.
    ScriptInterpreterSource registry
    Update 2: This is documented at the Apache website.

    - wil

      I bow before the master!

      Oh, P.S., That worked. This works perfectly! Nice thing is that it ignores the initial shebang line so I can leave it alone for my host Linux server to deal with.

      I remember looking at this directive long ago, understanding the *general* idea, but then wondering what it was really for. This is definately a great reason; they should list this as one of the primary uses...in more words, that is.

      Thanx

      ======================
      Sean Shrum
      http://www.shrum.net

Re: How do I...Fool Windows into using *nix formatted shebang
by Dog and Pony (Priest) on May 18, 2002 at 11:10 UTC
    It is easier than that. Install activestate in c:\usr instead of the odd default that they suggest. Then you can use the #!/usr/bin/perl shebang on windows too (as long as perl and apache is on the same drive, that is - can't have one on C: and one on D: with this).

    To take it for a test spin, just remove C: from your current shebang and see that it works.

    Actually, this one should really up on a windows Q&A, since ActivePerls stupid default to C:\Perl has caused so much grievance for people. Especially since it works anyway when you are not doing CGI stuff... :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.

      Only problem heere is that you are forced to use that path. The earlier suggestion works regardless of where you have Perl installed.

      P.S. I know this is coming a bit after the fact and twice as late but I figured I'd point out the downside of this approach.

      ======================
      Sean Shrum
      http://www.shrum.net

Re: How do I...Fool Windows into using *nix formatted shebang
by rbc (Curate) on May 18, 2002 at 19:01 UTC
    I hope this is helpful
    I asked a #! question a while back and got
    a lot of good feed back.

    You might also want to look into using Cygwin's port of perl
    and config Apache to use that instead of ActiveState.