• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Check if file is there???

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
nick2307
Asked:
nick2307
  • 3
  • 2
1 Solution
 
ozoCommented:
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
 
nick2307Author Commented:
what if file is not there.....then wait until it created...and then cntinue
0
 
ozoCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
nick2307Author Commented:
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
 
ozoCommented:
$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
 
ahoffmannCommented:
> this .NET application call my perl EXE.
why does it call your perl program when it not finished data for it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now