I want redirect output console program to memory. It can be specified memory buffer, or buffer that I can gert ptr to later. I need to specifiy input and output of program and can do this with tmp file+redirect I/O, but that expensive operations+invloves tmp files. I know redirect output to socket

startinfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
startinfo.hStdInput = sockfd;
startinfo.hStdOutput = sockfd;
startinfo.hStdError = sockfd;
CreateProcess(0, "cmd.exe", NULL, NULL, TRUE, DETACHED_PROCESS, 0, 0, &startinfo, &pinfo);

How do I redirect to memory?
also would like redirect input+err if possible

Recommended Answers

All 3 Replies

From when I programmed in C, I remember that output stream redirection is done by


a.out > filename.txt
or a.out < filename.txt

I don't remember which. One is input redirection, the other is output. I think the first is output.

From when I programmed in C, I remember that output stream redirection is done by


a.out > filename.txt
or a.out < filename.txt

I don't remember which. One is input redirection, the other is output. I think the first is output.

1) Yes, the first one is output
2) How does outputting to a file get the data into memory?

It's not enough to see one word (redirection) and come up with an answer, you must read the entire problem and understand the question before attempting to answer (redirection to memory)

BITMAN, AFAIK, there is no way to redirect to memory. And even if you could, what good would it do? Once the program is finished, the memory is gone -- so the output no longer exists. But, even if the program continues to run keeping the memory active, another program cannot access it because the memory of one program is not accessible by another program.

There is a concept called shared memory that you might look into, but you still have the problem of redirection.

I already know about redirect from cmd line, not asking that. I want redirect to memory in CreateProcess call. In code sample all i/o from cmd.exe redirected to socket, which is connect to server, so server control all i/o. in my code, I want redirect to shared memory, so after I call CreateProcess and process exits I get output of program in buffer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.