Superman has asked for the wisdom of the Perl Monks concerning the following question:

I have a CGI?PERL script that takes input from a form. The obtained entities are then used to declare 4 commands that need to be run, defined as $command1, $command2, $command3 and $command4. I then put these commands in an array my @programs($$command1, $command2, $command3, $command4); and open them using a filehandle open(@programs) { open(A,"$_")||die; while(A) { print; } close(A); } exit: However the above program does not run each command. Does any1 see a mistake?
  • Comment on How do i run several programs in the same perl script???

Replies are listed 'Best First'.
Re: How do i run several programs in the same perl script???
by arturo (Vicar) on Jul 25, 2001 at 19:13 UTC

    The basic facilities for running an external program from within any perl script are system and backticks. To execute an external program from within a perl script, use system "program name" (if you don't need to gather the output), and backticks `program name` if you do. If you need to get fancy and run these external programs in the background, read up on fork and exec.

    But let me warn you: unless you want to open up *very serious* security holes on your site, do NOT do any of this until you have read perldoc perlsec online version and *understand* it. To do otherwise is to virtually request trouble.

Re: How do i run several programs in the same perl script???
by Hofmator (Curate) on Jul 25, 2001 at 19:31 UTC

    Another way of capturing the output of an external program is:  open (CMD, "command |");. Read up on this with perldoc perlopentut.