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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wait for file-input.

Status
Not open for further replies.

Sajtz

IS-IT--Management
Apr 23, 2002
75
EU
Hi.

I´ve written a small script which waits for a file to be created. When it finally is created it goes thru some treatment...and finally it´s deleted...and goes back to waiting mode...

The problem is that i´m using a "while"-loop....and it kicks my cpu-usage up to the top (of course) though it´s a small program..

Is there a way to do this in a different and less cpu-consuming way?

Code

#!C:\Perl\bin -w

use CGI;
use strict;


my $html_file_path="testar.txt";
my $template_file_path="infile.txt";
my $log_file_path="outfile.txt";
my $pass;
my $connect;


print "\[HLTV-script is idling\]";
while (!-f $html_file_path)
{
if (-f $html_file_path)

{
open (INFILE, &quot;<$template_file_path&quot;) or die;
my @infile = (<INFILE>);
close (INFILE);

open (HTMLFILE, &quot;<$html_file_path&quot;) or die;
my @htmlfile = (<HTMLFILE>);
close (HTMLFILE);

foreach my $l_ (@htmlfile)
{

if ($l_ =~/^serverpassword/){
$pass=$l_;
}
if ($l_ =~/^connect/){
$connect=$l_;
}
}
open(LOGFILE,&quot;>$log_file_path&quot;) or die;
foreach my $line (@infile)
{
$line =~ s/\$serverpassword/$pass/g;
$line =~ s/\$connect/$connect/g;
print LOGFILE $line; # Output line to file
}
unlink $html_file_path;

}
close LOGFILE;
}
 
I would add an else statement to your first if statement that tells the script to sleep for a while before looping again.
Code:
while (!-f $html_file_path)
{
    if (-f $html_file_path)
    {
     # ... 
    }
    else 
    {
         sleep (1);
    }
}
jaa
 
hi.

That worked perfectly...thnxs a lot!

Now I have another problem...

I´m starting up a program in this script, and I´ve been using the system call..

system &quot;c:\\someprogram.exe&quot;:

The problem with this is that this starts up a server, and I want to finish it when I want to...

But since the system call apperently waits for the .exe to finish...it´s stucked....i can´t exit it...

Or can i?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top