Solved

Check if file is there???

Posted on 2006-11-09
6
184 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 84

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 84

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 84

Accepted Solution

by:
ozo earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 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