0

I am not at all proficient in unix or perl or cgi or apache but have been assigned to find a way to set an environment variable on unix from a cgi web page.

I can successfully set the Environment variable

$ENV{PROGPATH}=$Data{PROGPATH};

But when a 4ge program is launched and then itself launches another program, this variable seems to 'go away'. I think I need to run the command

export PROGPATH;

To make it 'stick' for the second program.

I can't seem to find a way to do this successfully from the cgi page that launches the first program.

2
  • 1
    Something like system("export $PROGPATH"); perhaps?
    – abiessu
    Feb 27, 2014 at 21:13
  • Actually abiessu, that works. I will mark it as a fix if you answer with this. Thank you.
    – Belmiris
    Feb 27, 2014 at 21:55

2 Answers 2

1

In Perl, the system command executes any given command intended for the command line. Here, it is necessary to export $PROGPATH and so the full command would be

system("export $PROGPATH");

Note that this might leave your system vulnerable to various attacks, so you may want to ensure that $PROGPATH gets sanity checked prior to this call.

1

Simple to do:

$ENV{FOO}=1;

system('echo FOO=$FOO');

When Perl runs system, it exports the variables to the forked process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.