Calling Perl gurus!

calbear2000

Golden Member
Oct 17, 2001
1,027
0
0
I have a perl program that makes a system call to run another tool. This tool can take anywhere between a few seconds to a few HOURS to complete... leaving me impatiently wondering if the other tool is still running or if the perl program crashed.

I'd like to do something like this pseudo code:

while (system "run other tool") {
print "..." every 5 seconds;
}

So I'll basically get a screen full of "............." while the perl is executing, assuring me that the other tool is still running. Any clever ideas?

And yes I can do a unix top to check the status... but I'd rather have a slick solution here :)




 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
how do you know if the other tool hasnt crashed or is stuck in an infinte loop?
 

calbear2000

Golden Member
Oct 17, 2001
1,027
0
0
Good question.

I can manually look at the tool's result area and do an "ls -lt" to see that the output file is being updated.

But I'm actually more concerned about my own script... which is why I'd like an automatic update of some sort.

Just not good enough with perl/unix to come up with something...
 

crystal

Platinum Member
Nov 5, 1999
2,424
0
76
Originally posted by: calbear2000
Good question.

I can manually look at the tool's result area and do an "ls -lt" to see that the output file is being updated.

But I'm actually more concerned about my own script... which is why I'd like an automatic update of some sort.

Just not good enough with perl/unix to come up with something...

If you know the name of the output file that been update, you could do a file test on in (in your perl program). If it update, then your program can terminate your program, otherwise, let it sleeps for 5 more seconds.

 

calbear2000

Golden Member
Oct 17, 2001
1,027
0
0
Originally posted by: crystal
Originally posted by: calbear2000
Good question.

I can manually look at the tool's result area and do an "ls -lt" to see that the output file is being updated.

But I'm actually more concerned about my own script... which is why I'd like an automatic update of some sort.

Just not good enough with perl/unix to come up with something...

If you know the name of the output file that been update, you could do a file test on in (in your perl program). If it update, then your program can terminate your program, otherwise, let it sleeps for 5 more seconds.

Good thought. But it brings me back to its implementation problem... perl won't run any other commands in parallel while making its system call.

 

notfred

Lifer
Feb 12, 2001
38,241
4
0
#!/usr/bin/perl

# set STDOUT to autoflush itsef.
select((select(STDOUT), $| = 1)[0]);

# Fork and get the child processes PID.
$pid = fork();

# Child runs this section.
if($pid == 0){

# Sub your system call in for this "sleep" statement.
sleep 10;

# When your proces sis finished, create "done" file.
print "\nChild is finished.\n";
open D, ">done";
print D "done";
close D;
exit;
}

# Parent runs this section.
else{
# Until the "done" file is found, print elipsis.
until(-e 'done'){
print "... ";
sleep 2;
}

# finish up, delete "done" file.
wait;
unlink "done";
exit;
}
 

calbear2000

Golden Member
Oct 17, 2001
1,027
0
0
Patience young notfred, patience :)

I got caught up with some work and didn't see your elegant solution here.

This is exactly what I was looking for. I knew perl would have some clever "fork" function to process commands in parallel. Thanks a lot for sharing your coding expertise.

Let me know what your paypal info is... I'll send you a little reward for your help