Put standard output into file

A

Alan Wang

Hi All,

My application puts standard output from command line(using process.start())
into a file on the hard disk then reads the info from that file after
command has finished. The problem is my program keep giving me the error
message saying that output file doesn't exits on the hard disk, but it's
there when I checked in the directory. I think there must be a delay on put
output file on the hard disk.

I am just wondering if anyone has solution for this type of problem except
using System.Threading.Thread.Sleep function. Any help is great appreciate.

Thanks in advance

Alan
 
C

Chris

Alan said:
Hi All,

My application puts standard output from command line(using process.start())
into a file on the hard disk then reads the info from that file after
command has finished. The problem is my program keep giving me the error
message saying that output file doesn't exits on the hard disk, but it's
there when I checked in the directory. I think there must be a delay on put
output file on the hard disk.

I am just wondering if anyone has solution for this type of problem except
using System.Threading.Thread.Sleep function. Any help is great appreciate.

Thanks in advance

Alan

Have you looked at using the FileSystemWatcher class to watch for when
your file is created? This will fire and event when the file is there.

There are lots of examples on using it. One is:
http://www.codeproject.com/csharp/fswatcher.asp

Chris
 
A

Andrew Morton

Alan said:
My application puts standard output from command line(using
process.start()) into a file on the hard disk then reads the info
from that file after command has finished. The problem is my program
keep giving me the error message saying that output file doesn't
exits on the hard disk, but it's there when I checked in the
directory. I think there must be a delay on put output file on the
hard disk.

Are you sure you're using the full (and correct!) path when you try to read
the file?

Andrew
 
A

Alan Wang

I am pretty sure I am using the right path because I didn't get problem when
I run the program in debugging mode because it has enough time to write data
back to the hard disk.

Alan
 
A

Alan Wang

The problem is FileSystemWatcher doesn't tell me when output file is ready
to be processed. In another words, I don't know how long I should wait to do
next step.

Alan
 
A

Andrew Morton

Alan said:
I am pretty sure I am using the right path because I didn't get
problem when I run the program in debugging mode because it has
enough time to write data back to the hard disk.

"Pretty sure" just doesn't cut it. How about putting up a message box with
the path in?
Or you could use filemon from www.sysinternals.com to see in what order the
activity associated with your file happens.
Otherwise you could check the length of the file and when it hasn't
increased for perhaps 500ms then try to read it?

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top