- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I am using a huge 'C' library to be build CFD app. The library contains fortran interfaces, so, I am willing to write a nice GUI in fortran to simulate a chemical process. The problem that arises is this one: The library contains a lot of printf streams and that goes nowhere in windows app. What I want to know is: Is there a way to redirect to a file [ open(6,.....) ?] or to a MessageBox those streams with fortran statements?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How about writing your own function, say my_printf, that processes arguments the same way as printf does but which then redirects output where you want them to go, some file or MessageBox, etc. instead of stdout?
You can then do a global replace using an editor for all your printf statements in code to use my_printf instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
One thing that I can't do is change the statement 'printf' on the 'C' libary. And that is because there are too many and the files are hundreds. So, the only way I have is to write some fortran code that grabs those messages from those streams or build a 'C' file to redirect it.I came here to have an insight about the best way of doing it.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've played with this, but memory fails me for specifics, so rambling follows. Anyway, you can use the Win32 API to redirect stdout from within a process. Depending on what the C runtime does (particularly during its initialiation), this may be sufficient. If not, an alternative is to set the redirection up in a wrapper process that sets the necessary pipes up before the program with the C library is executed.
See post #5 in this thread https://software.intel.com/en-us/forums/topic/356177, written for Fortran. The example creates a pipe, replaces stdout with the write end of that pipe and then creates a thread to listen to the read end of the pipe and shuttle whatever comes through somewhere else. This is all done in-process, so runtime initialization in a particular way might defeat it (because by the time stdout is intercepted the runtime may have already queried the relevant handles etc.
See post #9 in this thread https://software.intel.com/en-us/forums/topic/485615 for an example of redirection when creating a child processes, again written in Fortran. Specifically look at what the check_program_output procedure does.
You may be able to use C library functions to achieve the same - cant' recall whether they are standard or vendor additions that I've played with from time to time.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page