Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Executing a program or series of programs in perl.

by djantzen (Priest)
on May 09, 2003 at 03:42 UTC ( [id://256758]=note: print w/replies, xml ) Need Help??


in reply to Executing a program or series of programs in perl.

I take it you'd like to send one command off to do its work while you start another one? You should look at forking a new process for each task, or using threads to divy up the processing work. For instance, here's a quick and dirty start:

use strict; use warnings; use threads; my ($thr, @threads); INPUT: print "What do you want me to do?\n"; my $work = <STDIN>; chomp $work; if ($work eq "permissions") { $thr = threads->create(sub { print `sh /root/scripts/security.sh` }) +; push(@threads, $thr); #keep track of the thread print "security.sh sent into background\n"; goto INPUT; } elsif ($work eq "apachelog") { $thr = threads->create(sub { print `perl /root/scripts/apachelog.pl` + }); push(@threads, $thr); #keep track of the thread print "apachelog.pl sent into background.\n"; goto INPUT; } elsif ($work eq "exit") { $_->join() for @threads; # cause threads to return home after finish +ing. exit 0; }

Hope that helps.


"The dead do not recognize context" -- Kai, Lexx

Replies are listed 'Best First'.
Re: Re: Executing a program or series of programs in perl.
by mikey (Acolyte) on May 09, 2003 at 03:52 UTC
    "I take it you'd like to send one command off to do its work while you start another one?" Kind of. I want to be able to choose a task, (theres going to be several.) and while it performs it (in unix its known as sending the command to "the background") i want to pick a task and have it run but while it does, i want my shell back. Your comment did help a lot. so ill just take it from there using your code as a reference, thanks a lot. When im done with this script ill be sure and post it for all my fellow Unix junkies out there.. =]

      Hmm, Perl might well be overkill in that case. Why not just use aliases in your normal shell or symlinks?


      "The dead do not recognize context" -- Kai, Lexx
        Your absolutely right it may be overkill, BUT. perl CAN do it, and will do it well, and to be honest i want to learn perl real bad and this is one of the few things i could think of making to get me started.
      code@labs ~>> perl thread.pl thread.pl line 3: This Perl hasn't been configured and built properly for the threads module to work. (The 'useithreads' configuration option hasn't been used.) Having threads support requires all of Perl and all of the XS modules in the Perl installation to be rebuilt, it is not just a question of adding the threads module. (In other words, threaded and non-threaded Perls are binary incompatible.) If you want to the use the threads module, please contact the people who built your Perl. Cannot continue, aborting. BEGIN failed--compilation aborted at /usr/local/lib/perl5/5.8.0/mach/threads.pm line 28. Compilation failed in require at thread.pl line 3. BEGIN failed--compilation aborted at thread.pl line 3. code@labs ~>> Damn. I am the "people who built my perl." lol. looks like i have a job to do. Gotta get thread support built in.

Log In?
Username:
Password:

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

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

    No recent polls found