Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

How to exec in a separate thread?

by mr_leisure (Beadle)
on Jan 16, 2001 at 15:24 UTC ( [id://52214]=perlquestion: print w/replies, xml ) Need Help??

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: How to exec in a separate thread?
by Corion (Patriarch) 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: How to exec in a separate thread?
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: How to exec in a separate thread?
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: How to exec in a separate thread?
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://52214]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found