- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In my Windows MFC application I have a C++ main program that calls some FORTRAN libraries. Any ideas on how I could capture the output of a formatted FORTRAN unit ( specifically 6) ( if I can capture it I can redirect that to a log window).
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could use a console. The WinAPI function to create a console is AllocConsole(). Any windows task can create a console. Once created, the task can write to it as standard output (unit 6 or 0 or * in Fortran, usually). I do this from my Fortran DLLs called from Windows GUI programs written by other programmers (gets them somewhat spooked though...)
Qolin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See
Creating a Child Process with Redirected Input and Output
Of course, it will work only if unit 6 refers to the standard output (i.e. if there's not explicit OPEN(6)). And you probably don't need to redirect the application's input.
The CreatePipe technique will still holds even if the Fortran libraries are statically linked in. In that case, you don't need CreateProcess, but just SetStdHandle(hPipe) for your own application. However, note that pipe communication is synchronous, i.e. reading from a pipe won't be done until writing a complete record to it (i.e. Fortran WRITE(6,...)) is completed. If you want the log window to display the library's output in the same time it is WRITEn, you will have to launch the Fortran calculation in a separate thread.
Creating a Child Process with Redirected Input and Output
Of course, it will work only if unit 6 refers to the standard output (i.e. if there's not explicit OPEN(6)). And you probably don't need to redirect the application's input.
The CreatePipe technique will still holds even if the Fortran libraries are statically linked in. In that case, you don't need CreateProcess, but just SetStdHandle(hPipe) for your own application. However, note that pipe communication is synchronous, i.e. reading from a pipe won't be done until writing a complete record to it (i.e. Fortran WRITE(6,...)) is completed. If you want the log window to display the library's output in the same time it is WRITEn, you will have to launch the Fortran calculation in a separate thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the great ideas. Very helpful.
Andrew
Andrew

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