Home All Groups Group Topic Archive Search About

Put standard output into file

Author
12 Jan 2006 3:26 PM
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

Author
12 Jan 2006 4:45 PM
Chris
Alan Wang wrote:
Show quoteHide quote
> 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
Author
12 Jan 2006 6:51 PM
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


Show quoteHide quote
"Chris" <no@spam.com> wrote in message
news:uLBWYe5FGHA.1180@TK2MSFTNGP09.phx.gbl...
> Alan Wang wrote:
>> 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
Author
12 Jan 2006 5:19 PM
Andrew Morton
Alan Wang wrote:
> 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
Author
12 Jan 2006 5:59 PM
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
Show quoteHide quote
"Andrew Morton" <a**@in-press.co.uk.invalid> wrote in message
news:OwHvzx5FGHA.3856@TK2MSFTNGP12.phx.gbl...
> Alan Wang wrote:
>> 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
>
Author
13 Jan 2006 9:29 AM
Andrew Morton
Alan Wang wrote:
> 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

--
PS: You might like to use OE-Quotefix so that your Outlook Express replies
in the conventional format.
Author
13 Jan 2006 12:00 PM
Jevon
Why do you put it into a file, rather than reading straight from the memory
stream? Have you read through
http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx ?
Jevon


Show quoteHide quote
"Alan Wang" <w***@vdata.com> wrote in message
news:%23PkBby4FGHA.1676@TK2MSFTNGP09.phx.gbl...
> 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
>