|
Posted by Ben Morrow on February 29, 2008, 2:49 pm
Please log in for more thread options
>
> >> > run_command('source init_file');
> >> > run_command('mycommand.pl -configfile config -exec ');
> >>
> >> I'm guessing that you are trying to read some environment variables
> >> from init_file before running mycommand.pl?
> >>
> >> That won't work. First problem is that source is a shell builtin and
> >> not an independent program, this is why you are getting an
> >> error. Another problem is that child processes can't set environment
> >> variables if the parrent process and even if source was a real
> >> program, it couldn't set the environment for mycommand.pl
> >
> > I understand, so it is better for this purpose to write a shell
> > script .
> > Thank you very much for your quick answer,
>
> Not necessarily. You could do something like this:
>
> run_command(qq!sh -c "source init_file; mycommand.pl -configfile
> config -exec" !);
This is somewhat pointless. Simply using perl to run sh for you is
evidence that sh would have been a better tool in the first place :).
The module Shell::GetEnv will allow you to extract the environment from
a subshell:
use Shell::GetEnv;
Shell::GetEnv->new(sh => 'source init_file')->import_envs;
run_command 'mycommand.pl...';
Also, the IPC::Run module is a much more convenient and reliable way of
running external commands that rolling your own using system.
Ben
|