Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processing java programs with Perl.

Status
Not open for further replies.

Kevster

Programmer
Feb 28, 2001
1
US
I have seven Java programs that need to run automatically. I've created a batch file which will run each program. Each program produces a output file which executes the next Java program. I'm having a hard time creating it in perl.

First:
Execute first Java program

Loop:
Searching for output file
Sleeps ((for one min))
Output file created
goto second

Second:
Execute second Java program
Loop:
Searching for output file
Sleeps ((for one min))
Output file created
goto third ((Exc.

Basically what's happening is:

Execute first program, then process through the loop until the output file is created. Once the output file is created, process second Java program. Then process through second loop untill the output file is created. The same process is used all the way through the seventh program.

If someone can help, it would be much appreciated.
 
here's a subroutine i use, slightly modified for your situation. note that in its current form, if any java program never creates its output file, the loop "while (1)" will go on forever. you may want to make a 10 minute limit with a "foreach (1..10)" instead. to call this subroutine, the first argument is the commandline string to be executed, something like "progname -l", or whatever, and the second argument it needs is, in your case, the full directory path and file name that the program will create as output (and i assumed unix style directory listings).
[tt]
sub readprog
{
my $prog = shift or die "Command?\n";
system "$prog";
my $outputfile = shift or die "Condition?\n";
$outputfile =~ m~(.*/)(.*?)$~;
my $dir = $1;
my $filename = $2;
while (1)
{
opendir DIR, "$dir";
if (grep m~^$filename$~, readdir DIR)
{
closedir DIR;
last;
}
closedir DIR;
sleep(60);
}
}
#then just call it for each program name
&readprog("prog1 -o", "/home/user/dir/file.out");

#etc...[/tt]

if you wanted to open them all simultaneously-like, you could do cool piping of child processes and stuff, but i don't have any examples, and only really a vauge idea of how to anyway, from the camel book. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top