Gfortran file open problem / console input

I have windows (winmain) application I build in Intel Fortran. I recently set up a build in gfortran which works OK but I have a strange problem. The application in the initialisation phase opens (via create process) a console window and configures it ( size, location, title, icon, colour scheme, buffer size etc…) . The console is attached to the application using the windows api AttachConsole function. This console is used for informational output only. The main application thread is a (GDI) window with menus etc which can also have OpenGL child windows, modal and modeless dialogs etc etc.

Anyway every time I open a file with a Fortran OPEN statement the program appears to hang. What I find is that I have to click on the console window and hit enter. The file open then happens correctly without any error status. It is like it wanted to pop some invisible console message and I need “enter to continue”. Has anybody got any ideas what causes this of how to investigate the root cause? I am guessing it is some feature or quirk of the gfortran runtime system.

Can you post a small reproducer? Do you use Cygwin or MinGW as the build environment?

It was built in a windows command window using a batch file. I don’t have/use Cygwin or MinGW environment. A reproducer would be possible but would be quite a bit of work as there are several hundred thousand lines of code over many files and modules I was initially hoping for some inspiration…

Understood - pity, though, because that would have made some experimentation easier.

I have no experience myself with AttachConsole, but what happens if instead of a WinMain, you use an ordinary main program and start a window from that? I know a WinMain will set up things more automatically, but it is not the only way.