Mailing List Archive

Firing up Perl from execle()
Someone here might have played with this and know the answer.

I've a perl script with a header like this:

------
#!/usr/local/bin/perl -I /Users/amon/private_html/cgi-bin

etc
-----

Which is execle'd from a test program. Without the -I the process
always runs. With it, in usually doesn't on my home machine but
sometimes if I subshell (I'm already running in a csh by default)
it runs. If I go in via gdb I find that if I bpt just before the
call, and then continue, it usually works after giving a trap
which I also proceed from, but if I just run it it fails.

Have you had any similar long nights with execle()?

BTW - I'm passing it an environment with the SHELL set to /bin/csh.
Re: Firing up Perl from execle() [ In reply to ]
Excerpts from the mail message of Dale Amon:
) #!/usr/local/bin/perl -I /Users/amon/private_html/cgi-bin

The general rule is that many versions of Unix can't handle more
than 32 characters in a #! header and then will pass the first two
words after "#!" followed by the script name. This gives you:

exec /usr/local/bin/perl -I scriptname

You should instead use:

#!/usr/bin/perl
use lib '/Users/amon/private_html/cgi-bin';

[.and have /usr/bin/perl point to /usr/local/bin/perl as the install
process suggests.]

If you can't get perl5.001m which includes "use lib", you can
also do this (in perl5.x):

#!/usr/bin/perl
BEGIN { unshift( @INC, '/Users/amon/private_html/cgi-bin' ); }

You could also do something like this but I don't recommend it:

#!/usr/local/bin/perl5.001 -- # perl -I/Users/amon/private_html/cgi-bin

(Note that this puts the directory at the end of @INC unlike all
of the previous examples.)

There are also several perl4 tricks that will work but I won't go
into them.

) BTW - I'm passing it an environment with the SHELL set to /bin/csh.

Since you're exec'ing the script from a program (not a shell), I
don't think this should matter unless your Unix kernel doesn't
support "#!" at all. However, some versions of csh do #! support
themselves and csh is notorious for getting stuff like this (and
many other things) wrong.
--
Tye McQueen tye@metronet.com || tye@doober.usu.edu
Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)