QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Ed Davis on March 23, 2019, 11:15:46 am
-
I do most of my work from a Windows command prompt/console box.
It would be nice for certain QB64 programs that I write, if all output went to the console window that I'm working in.
Using notes I found on the Wiki, I was able to get it to work:
If run while in a command prompt, all output goes to that command prompt. Just what I wanted.
However, one problem remains: If I start the program from an icon, or via an explorer window, the window is closed after the program is finished (because of the system command).
How can I tell if my program was started from a console prompt or not, so I can selectively issue the system command?
-
Simply pass a agruement to your program when running from CMD, like "yourProg.exe foo".
Then use COMMAND$ in your code to check whether it was run from console window.
-
Simply pass a agruement to your program when running from CMD, like "yourProg.exe foo".
Then use COMMAND$ in your code to check whether it was run from console window.
I appreciate the reply, but I don't want to have to pass a parameter.
In a Windows program written in C - one that uses the GUI subsystem, e.g., WinMain() instead of main(), one can call AttachConsole(ATTACH_PARENT_PROCESS), and if the function returns nonzero, the GUI program was started from a command prompt.
However, when I try this from QB64, it always returns 0, no matter how the program was started.