[HRPM] quick question

chicks at chicks.net chicks at chicks.net
Sat Oct 28 12:16:19 CDT 2000


On Sat, 28 Oct 2000, Troy E. Webster wrote:
> Hey what's the most painless way to launch a seperate perl script from
> inside another? I need to pass the seperate script one scalar. PS I'm
> not using oop here. 
> 
> I also need to launch a C program from within. Is it done the same way? 
> 
> My first thought was to just use system, as in:
> 
>  @args = ("command","arg1","arg2");
>     system(@args) == 0
> 	 or die "system @args failed: $?"
> 
> Am I thinking about this the right way?
> 
> Any thoughts are appreciated. 

BTW - That's the best way to use system().  If @args has only one element
or if you pass a scalar directly to system, it may get invoked by the
shell which is a security hazard.

And system() is a good choice if you don't need any output from the
command and the command isn't going to produce any output.  If the command
is going to produce output, you may want to use open(FH,"$cmdlin |")
instead.  If you don't need the output you can always throw it away.  If
the command is going to produce output on STDERR that has to be redirected
somewhere you're back to using the system() call with a scalar that will
get invoked by the shell.

-- 
</chris>

"The number of Unix installations has grown to 10, with more expected." 
           -- The Unix Programmer's Manual, 2nd edition, June '72




More information about the Norfolk-pm mailing list