control vICQ via Perl

E

Eric

Hi everyone,

I'm trying to write a rather simple Perl script to read output from
and write input to vICQ, a small ICQ console client. I know tat vICQ
itself is written in Perl, but I'm looking for a way to communicate
with other programs also, so I won't change vICQ's source.
The idea is to launch vICQ in my Perl script using IPC::start() and
then process its output (i.e. ICQ messages sent to this machine) in
intervals of, say, 30 seconds. Depending on this output I want to send
a message back to the other machine.
I read about doing this with pipes, but these don't seem to work for
me (see also http://www.thescripts.com/forum/thread49897.html), so
right now I'm using simple scalars as input/output buffers. The only
problem is that after a pump() new output (if available) is just
appended to my $out scalar. So how can I determine if there is new
output available since the last check? And will this scalar get
infinetely long, limited only by my RAM?

Thanks for any help,
Eric

p.s.: vICQ doesn't include timestamps in its output, so I can't
distinguish wether a message was sent once or repeatedly.
 
E

Eric

So far, I have the following script:


use IPC::Run qw ( start );
use IO::Handle;

my @msg_name=();
my @msg_text=();

my $in,$out,$err;
my @cmd=qw( vicq -b -o -t 2 );
my $h = start
\@cmd,
\$in,
\$out,
\$err;
$in .= "msg 123456789/Listening...\n";
pump $h;
for(my $i=0;i<5;$i++) {
sleep(10);
pump $h;
@msg_name=();
@msg_text=();
while($out=~ /Instant message from (.+?):\n((.|\n)+?)\ntext_message/
g) {push(@msg_name,$1);push(@msg_text,$2);}
while($#msg_name>=0) {print shift(@msg_name)." wrote:
".shift(@msg_text)."\n";}
}
finish $h;


vICQ is started with some parameters. The script then messages another
machine that it is ready to read input. The for-loop is just for
testing purposes so my script won't run forever.
The first while-loop scans vICQ's output for an instant message event
and pushes author and text on the two arrays. The second one, also
just testing, prints out the results.
But since new output is just appended to $out, all messages that have
arrived so far are printed every 10 secs, not just the new ones.
Any ideas how to change the start() call to read sequentially?

Greets,
Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top