PDA

View Full Version : running a script withen a script


ignoranceisblis
03-03-2005, 03:32 PM
Could someone give me an example of how to run a perl script inside another perl script

I can go

system('perl /home/script.pl');

and

$command = `perl /home/script.pl`;
print $command;

but both of those tend to emulate the bash prompt and so special charactors like ? ' " must be removed first,
is there a way to run it more smoothly?

mlseim
03-03-2005, 05:58 PM
Are you saying so that the first script runs a second script and both
are then running at the same time?

Or, does the first one start the second one and the first one ends?

ignoranceisblis
03-03-2005, 06:41 PM
the first script runs and then runs the second in the background, both scripts are rnning at the same time

mlseim
03-03-2005, 08:12 PM
Some servers allow shell commands, where the Perl script executes
a UNIX command from within. This is not what you're talking about ...
You want two scripts to run at the same time. This is not really
possible ... but there is a thing called "forking", where a parent script
can begin a child script and both end up running simultaneous. The
parent script can then for example, return control back to the browser
while the child script continues to crunch some numbers.

Forking ends up being one script though ... It sounds like you might
be trying to execute two totally separate scripts at one time.

Maybe if you explain why the two must run together, there might be
another solution to your problem.

ignoranceisblis
03-03-2005, 09:35 PM
I had previously made the a.i. 'arty.cgi' to run in a tiny little web interface that I made myself. Eventually I made a TCL script to put arty on IRC through eggdrop, and a small interface to talk to him right at your bash prompt.
Now I'm using the Net::AIM module to connect arty to AIM.

all of the different interfaces use the same arty.cgi script which basically goes as follows:

perl arty.cgi 'user=Elliot&externalfile=bashtalking&talk="this is what I amm saying to arty"';

#his response is then stored in 'bashtalking'

perl display.cgi 'file=bashtalking';

# this reads the file

in this way I can devot a file to each interface (i.e. IRCtalking, WEBtalking, bashtalking)

the problem I'm running into is with AOL Instant Messenger

this the peice of code that is giving me problems

# this script is called arty_on_aim.pl

# what he does when someone send him a message
sub on_im {
my ($self, $evt, $from, $to) = @_;
my $args = $evt->args();
my ($nick, $auto_msg, $msg) = @$args;
my $stripped = $msg;
my $active="no";
#strip out HTML that might be sent along.
$stripped =~ s/<[^>]+>//g;
$stripped =~ s/^\s+//g;
chomp($msg);
my $newmsg=$stripped;
# because the way I call 'arty.cgi' emulates a
# bash prompt I cannot have any of the charactors below
$newmsg =~ s/\?//g;
$newmsg =~ s/\'//g;
$newmsg =~ s/\"//g;
$newmsg =~ s/\{//g;
$newmsg =~ s/\}//g;
$newmsg =~ s/\[//g;
$newmsg =~ s/\]//g;
# take the spaces out of the user messaging arty
$nick =~ s/ //g;
# add the user to the "active users" file
open(ACTIVE,"/var/www/cgi-bin/arty/activeusers") or print("sorry, no go\n");
flock(ACTIVE, LOCK_SH);
seek(ACTIVE, 0, SEEK_SET);
while (my $activeline =<ACTIVE>) {
if(($activeline =~ /$nick\n/)||($nick =~ /$activeline/)||($activeline eq $nick)) {
$active="yes";
}
}
close(ACTIVE);
if($active eq "no"){
open(ACTIVE,">>/var/www/cgi-bin/arty/activeusers");
flock(ACTIVE, LOCK_SH);
seek(ACTIVE, 0, SEEK_SET);
print ACTIVE "$nick\n";
close(ACTIVE);
}
print "$nick: $stripped" , "\n";
print PHRASE "$nick: $stripped" , "\n";
my $send_bool="TRUE";
$buddies=$nick;
$aim->add_buddy($send_bool, $group, $buddies);

# here is the problem, I need a different way of executing those two perl script
$artyresponse=`perl arty.cgi'externalfile=AIMtalking&user=$nick&talk=$newmsg'`;
$artyresponse2 = `perl bashdisplay 'externalfile=AIMtalking'`;
$self->send_im($nick, "--> $artyresponse.");