SubSystem Windows application launched from a DOS shell

SubSystem Windows application launched from a DOS shell

I'm compiling a GUI application, and have set the SubSystem to /SUBSYSTEM:WINDOWS.  This has the normal behavior of not opening a command shell when the application is launched by double clicking it.  However, what I would like is this: when the application is launched from a command shell (cmd -> cd to the exe directory -> type exe name), I would like write(*,*) statements in the code to show up in the shell.  Currently, of course, they do not appear.  Basically, I want to build one executable that can be used as a normal application, but also has a command-line mode when launched from a DOS shell.  Is such a thing even possible?

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I use the sdk function AttachConsole to attach an existing console window to my application (you need the process ID of the console) and then use the writeconsole function to output to it.  But  it would be easier writing a console application read :


I would have thought it simpler to just have two executables, even if all the command prompt variety does is call the GUI variety with the standard output handle redirected.

Do you have an example of using AttachConsole from Fortran?  I'm not seeing an interface to this routine in the Intel WinAPI modules.

I'd like to avoid having two executables.  I'd rather just have one exe that has a console only when used in command line mode.  Or maybe there's a way to compile with subsystem:console, but hide the console window somehow when the exe is launched by double-clicking it?

Thanks!  I ended up getting something to sort of work:

  function AttachConsole(dwProcessId)
   integer(bool) :: AttachConsole
   integer :: dwProcessId
  end function AttachConsole
 end interface	

 logical :: stat

 stat = AttachConsole(-1)

The only problem is the issue mentioned here:  I'll tinker with it some more.  It's an OK solution (having to press Enter is annoying, but maybe that's the best that can be hoped for).


glad you made some progress. BTW mixing integer and logical (stat) is wrong in my book and I use compiler settings that would make this an error, I think warn interfaces would do this....

Agreed.  Thanks!

Leave a Comment

Please sign in to add a comment. Not a member? Join today