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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirect output to memory/heap 2

Status
Not open for further replies.

jbs

Programmer
Feb 19, 2000
121
US
I would like to programmatically start a child program and have its output directed to memory versus the screen. For example, let’s say I want to have the output of the program “ipconfig” be directed into a buffer in memory vice having it display the results on the monitor. I know how to create a child process and wait for it’s completion, I know how to create memory space via the heap, however I don’t know how to:

1) redirect the output to memory
2) Have the heap area increased as more memory is needed for the ouput (for example, assume I don’t know the number of lines needed to output the command “ipconfig /all”.


I’d greatly appreciate any help that can be provided.

Thanks,

Jerry
 
try looking at the CMemFile MFC class. This is kind of like a 'file' that exists in memory instead of on disk. Once you have written data to the file (just like writing to hard disk) you can pass it around to other functions or whatever for further processing.
Some other function can then 'read' the data from the file or add to it or whatever.

[rockband]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
I should have mentioned, this is a non-MFC program (i.e. assume a simple win32 console based application).

Any ideas?

thanks,
Jerry
 
You want to use CreateProcess() and setup the STARTUPINFO structure to contain a output HANDLE that the child process will use. There are some exceptions and many more details that need attention.

Search MSDN for some of those key words, maybe all. There was a really old Knowledge base article that has very specific information, code and warnings regarding the behavior of child processes and the various ways they may or may not produce console output.

Good luck
-pete
 
You dont want output to the screen - ok, why don't you like output to the file on disk? Why to the memory?
system("ipconfig > out_file.txt")
 
I'd like the child application to create a process that will store it's output in memory so that the main program can use it. The advantage of it going directly into memory of course is high access speed and I can avoid all issues related to create new files in various places....for starters. There are other advantages and this isn't the first time I've run into this problem.

Please let me know if you have any additional ideas....thanks/j
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top