Solved

Check if file is there???

Posted on 2006-11-09
6
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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