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 variableNo 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