embedded perl path $ENV{PATH} problem

R

R. Sherwin Kartick

I have embedded perl in my c program, however I have encountered a
problem where the $ENV{PATH} can only be updated in the first
PerlInterpreter instance.
I get "unable to start foo.sh: No such file or directory at -e line
2." It appears perl is not using the updated PATH.

I am using perl 5.8.0, compile-time options: DEBUGGING MULTIPLICITY
USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT on Red Hat
Enterprise Linux WS release 3 (Taroon Update 1).

The following is from the docs with modifications to show the problem:

#include <EXTERN.h>
#include <perl.h>

#define SAY_HELLOA "-e", "print qq(Hi, A I'm $^X\n)"
#define SAY_HELLOB "-e", "print qq(Hi, B I'm $^X\n); $ENV{PATH} .=
\":/home/username/foo\"; open(FOO, \"foo.sh |\") or die \"unable to
start foo.sh: $!\"; close FOO;"
int main(int argc, char **argv, char **env)
{
PerlInterpreter
*one_perl = perl_alloc(),
*two_perl = perl_alloc();
char *one_args[] = { "one_perl", SAY_HELLOA };
char *two_args[] = { "two_perl", SAY_HELLOB};
PERL_SET_CONTEXT(one_perl);
perl_construct(one_perl);
PERL_SET_CONTEXT(two_perl);
perl_construct(two_perl);
PERL_SET_CONTEXT(one_perl);
perl_parse(one_perl, NULL, 3, one_args, (char **)NULL);
PERL_SET_CONTEXT(two_perl);
perl_parse(two_perl, NULL, 3, two_args, (char **)NULL);
PERL_SET_CONTEXT(one_perl);
perl_run(one_perl);
PERL_SET_CONTEXT(two_perl);
perl_run(two_perl);
PERL_SET_CONTEXT(one_perl);
perl_destruct(one_perl);
PERL_SET_CONTEXT(two_perl);
perl_destruct(two_perl);
PERL_SET_CONTEXT(one_perl);
perl_free(one_perl);
PERL_SET_CONTEXT(two_perl);
perl_free(two_perl);
}


This program will fail, yes foo.sh exists and it is not in my initial
path. However, if you run SAY_HELLOB in the the first interpreter
everything will work!

char *one_args[] = { "one_perl", SAY_HELLOB };
char *two_args[] = { "two_perl", SAY_HELLOA};

Any ideas, suggestions. I have tried this on win32 and it works fine.

thanks ... sherwin
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top