Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check if file is there???

Posted on 2006-11-09
6
Medium Priority
?
200 Views
Last Modified: 2013-12-25
Hi,

I have one perl aaplication that takes XML file that is created as a result file. There are huge data that will be created in this XML result file. so its taking some time to fully write data and create it.
meanwhile my perl application take this XML result file as input. So, sometimes it gives error that file is not there and sometimes it take file as a input.

How can I put a checkmark that is the file is fully created then and then only take that filename & path as argument and pass it on as Input.

Please advise....
Its Urgent...
 
0
Comment
Question by:nick2307
  • 3
  • 2
6 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 17910369
if( -f $file ){
   print "$file exists\n";
}else{
   print "$fine does not exist\n";
}

Or you can lock the file in one application, and wait for the lock in another application
see
perldoc -f flock
0
 

Author Comment

by:nick2307
ID: 17910487
what if file is not there.....then wait until it created...and then cntinue
0
 
LVL 85

Expert Comment

by:ozo
ID: 17910513
for example

#in one application
use Fcntl ':flock'; # import LOCK_* constants
open RESULT,">file" or die "Can't create file $!";
flock RESULT,LOCK_EX;
print RESULT "data\n";
close RESULT;



#in another application
use Fcntl ':flock'; # import LOCK_* constants
if( open INPUT,"<file"  and flock INPUT,LOCK_SH and -s INPUT ){
    print "the file is fully created\n";  
}else{
    print "the file is fully created\n";  
}
close INPUT;
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 

Author Comment

by:nick2307
ID: 17910541
I dont think I can do this...as the other application that create XML result file is in .NET and I dont handle it. this .NET application call my perl EXE.

So is there any way I can change my perl coding....and do this....

I am taking file name & path as:
$xmlfile = $ARGV[0];
my $ref=XMLin($xmlfile);


0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 17910598
$xmlfile = $ARGV[0];
while( ! -s  $xmlfile ){
   warn "waiting for $xmlfile";
   sleep 3;
}
my $ref=XMLin($xmlfile);

but are you saying that the .NET application calls the Perl application before it has finished creating the file?
Can you write another Perl application that calls the .NET application?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17921991
> this .NET application call my perl EXE.
why does it call your perl program when it not finished data for it?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question