How to get at the perl options

S

sharma__r

...
then write a short wrapper script (in shell or c or even perl) to
call/exec perl and the script. don't do this in perl itself or you run
into your problem. if you split this into two things it becomes easy.
I'm not sure why it was included in the strawberry distro
but there's an example which could be easily modified:
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
//
//  wrap perl executable
//
int main (int argc, char* argv[]) {
    const char* perl_cmd = "C:/strawberry/perl/bin/perl.orig.exe";
    char* perl_args[argc];
    int i;
    FILE *fp;
    // perl_args[0] = argv[0];
    // for( int i = 1;  i <= argc;  i++ ) {
    fp = fopen("c:/temp/prog.log", "a");
    if (fp == NULL) {
        printf("C:/temp/prog.log couldn't be opened...");
        exit(1);
    }
    for( i = 0;  i <= argc;  i++ ) {
        printf("arg %d = %s\n", i, argv );
        // perl_args[i+1] = argv;
   }
   fprintf(fp,"%s was called...\n",argv[1]);
   argv[0] = perl_cmd;
   fclose(fp);
   //return execv( perl_cmd, perl_args );
   printf("exec'ing binary %s with arg %s...:  %s\n", argv[0],argv
[1] );
   return execv( perl_cmd, argv );
}

This doesn't solve my problem. The scenario when the script gets
executed
by the perl binary, as:
   perl [perl options] myScrit.plx [script options]
would still pick the whatever perl version is ordained by
the PATH variable
No amount of wrapper logic would solve this unless there's found a way
to recall what options were provided to perl. We already have @ARGV
for
the the script options.

Without modifying Perl to provide access to all its
commandline options (which would be useful), there
doesn't  appear to be an easy way.

An ugly alternative might be to force the non-standard
invocation to re-specify the perl commandline:

[untested]

BEGIN{
   ...
   if ( !exists $ENV{_perl_wrapper} || !defined ... ) {
      print "Sorry, you'll need to re-specify any "
            "options you used to invoke perl>";
      chomp( my $opts = <> );
      ...
      exec("perl $opts -w -S \"@ARGV\" -- $0"); # ..
   }

}




Thanks to everyone who took the time to reply & clarify my problem.
Really appreciate it.
I have got some good leads all due to you guys.

--Rakesh
 
T

Ted Zlatanov

BM> Or just write a little bit of XS to grab PL_origargv and PL_origargc.
BM> You need to make sure you look at them before anyone gets a chance to
BM> assign to $0, though, since those assignments reuse that memory (for
BM> obvious reasons).

Ilya, would that be sufficient in your opinion? Devel::OriginalARGV?
I'll write it if no one else wants to.

I can't think of plausible security issues, since the script can already
look at the process list in almost all cases as Oliver and others
pointed out. Any opinions?

Ted
 
C

C.DeRykus

...
BM> Or just write a little bit of XS to grab PL_origargv and PL_origargc.
BM> You need to make sure you look at them before anyone gets a chance to
BM> assign to $0, though, since those assignments reuse that memory (for
BM> obvious reasons).

Ilya, would that be sufficient in your opinion?  Devel::OriginalARGV?
I'll write it if no one else wants to.

I can't think of plausible security issues, since the script can already
look at the process list in almost all cases as Oliver and others
pointed out.  Any opinions?

Great idea. I'm sure it would delight many more
if it were a magic variable from the Perl core
but that's a mission for another day :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top