http://www.perlmonks.org?node_id=52214

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Subroutines
by Corion (Pope) on Jan 16, 2001 at 15:34 UTC

    exec() is not what you want. What you may want instead are either fork() or system() or do().

    Some examples (without error checking, do a Super Search on each of these things to find out more):

    system( 'print.pl' ); # starts print.pl and continues when print.pl finishes # or alternatively do( 'print.pl' ); # Runs print.pl as if the text was typed instead of # the do(...) line # or alternatively a version which is semi-portable to # Windows as fork() dosen't really work there my $pid; $SIG{CHLD} = sub { wait }; if ($pid = fork()) { # I am the master, so I continue here } else { # I am the child, so I print };

    If you really really really want to use fork(), I recommend you use the Super Search and read the man pages about it, because there is much more to fork() than what I've touched on here.

Re: Subroutines
by mirod (Canon) on Jan 16, 2001 at 15:37 UTC

    Alternatively you might want to have a look at Proc::Daemon which might do just what you want

Re: Subroutines
by Elgon (Curate) on Jan 16, 2001 at 17:22 UTC
    If you are trying to get input from the standard output of the script and system security is good (NOT one of my best topics) then why not use backticks, as in...
    $foo = 'usr/bin/bar.pl';

    If anyone has any good reasons why not, please reply or /msg me.

    Muchas gracias, Elgon

    UPDATE: Thanks to myocom, that should read...

    $foo = `/usr/bin/bar.pl`;

    Goddamn azerty keyboards!

      Just two problems with your code: $foo = 'usr/bin/bar.pl';

      One, those aren't backticks. Two, you probably want a leading / in your path, there...

      $foo = `/usr/bin/bar.pl`;
Re: Subroutines
by lzcd (Pilgrim) on Jan 17, 2001 at 02:30 UTC
    And remember kiddies:

    Don't run with knives

    And don't run any of the above in a CGI unTainted. :)
A reply falls below the community's threshold of quality. You may see it by logging in.