- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- 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
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Agreed. Thanks!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page