Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting File Output to Memory 1

Status
Not open for further replies.

woogoo

Programmer
Joined
Feb 14, 2004
Messages
247
Location
GB
Hi all,

as part of a process I launch, a log file is created on disk, is there anyway I can have this output redirected to memory so no file exists, even though the process thinks it's writing to disk?

Any help would be really appreciated.

--
Thanks.
 
It may not be the best solution but what you're asking for seems more so like just writing the log to a locally declared space (variable) until the time is required to actually create the file out of it. That would in reality be writing it to memory until you what it to be written to disk

?

____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood

 
Use the System.IO.MemoryStream object instead of a FileStream object. Here is an example:

Code:
      Dim ms As New System.IO.MemoryStream
      Dim fo As New System.io.StreamWriter(ms)

      fo.WriteLine("Log File Contents.")
      fo.Flush()
      fo.Close()
 
This isn't going to work as the API I use expects a string to define the filename, for example "c:\logs\output.log"

What I'm looking for is the same as the Unix devnul. What would work is if this memorystream could be implemented to 'pretend' to be c:\logs\output.log
 
You can try using "C:\NUL" or "\\.\C:\NUL" with your API and see if the API supports it. This is supposed to be the equivelant of the dev\null file in UNIX, but not all APIs support writing to this file. The .Net FileStream object is one example of an API that does not support this model.

Another option is to just use randomly generated temp files for your log and clean them up after you are done. This may or not help you with your problem, but it may be your only solution if you are limited to the functionality of an existing API.
 
stravis,

the 'c:\nul' works thanks.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top