c - Internally capture/redirect stdout? -


It looks like a computing system 101 question, but I've been stumped.

I am integrating existing code from Project A to C / C ++ Project A in my own project. Both A and B will be connected to an executable, threaded process. The use of printf is widely used for code A of the project A. That's fine, but I also want to capture that production in my buffers. Can printf calls be written once, can I read from studs? I can not process or pipe fork and my efforts for the choice () stdout, or dup () have not been successful (I am doing something wrong).

You can use to change the descriptor.

  # include & lt; Stdio.h & gt; Main (int argc, char ** argv) {FILE * fp = freopen ("output.txt", "w", stdout); Printf ("hello \ n"); Fclose (fp); }   

If you run you will see printf output in output.print and nothing will go to your screen.

Now you can open the file to read the data or you can bring it in your memory space and process it like this.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

c# - Confused over DLL entry points (entry point not found exception) -