Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

SubSystem Windows application launched from a DOS shell

Jacob_Williams
New Contributor I
558 Views

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?

0 Kudos
7 Replies
andrew_4619
Honored Contributor III
558 Views

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 :

https://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-win/GUID-CF3F975E-3BBB-4777-88FE-5D2A314BFDD2.htm

 

0 Kudos
IanH
Honored Contributor II
558 Views

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.

0 Kudos
Jacob_Williams
New Contributor I
558 Views

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?

0 Kudos
andrew_4619
Honored Contributor III
558 Views
0 Kudos
Jacob_Williams
New Contributor I
558 Views

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

 interface
  function AttachConsole(dwProcessId)
   import
   integer(bool) :: AttachConsole
   !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'AttachConsole' :: AttachConsole
   integer :: dwProcessId
  end function AttachConsole
 end interface	

 logical :: stat

 stat = AttachConsole(-1)

The only problem is the issue mentioned here: http://stackoverflow.com/questions/12943463/how-to-create-a-c-mfc-program-that-can-boot-in-both-gui-dialog-mode-or-through ; 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).

 

0 Kudos
andrew_4619
Honored Contributor III
558 Views

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....

0 Kudos
Jacob_Williams
New Contributor I
558 Views

Agreed.  Thanks!

0 Kudos
Reply