# Console or GUI at the same time

**URL:** <https://forum.juce.com/t/console-or-gui-at-the-same-time/46369>\
**Category:** General JUCE discussion\
**Created:** [June 7, 2021, 10:19am UTC](https://forum.juce.com/t/console-or-gui-at-the-same-time/46369 "2021-06-07T10:19:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yndurain](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yndurain/32/3261_2.png) [@yndurain](https://forum.juce.com/u/yndurain)\
**Post date:** [June 7, 2021, 10:19am UTC](https://forum.juce.com/t/console-or-gui-at-the-same-time/46369/1 "2021-06-07T10:19:13Z")

</div>

Hello,

I have an app that I want to launch as a GUI if you execute it with no parameters or as a console app if you pass some parameters.

It works ok-ish as when I launch the GUI it also has a console window in the background. How can I avoid this window?

So if I call c:\> myapp.exe → shows GUI (and only GUI, no console)  
if I call c:\> myapp.exe par1 par2 par3 → shows console

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![darrenwin](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@darrenwin](https://forum.juce.com/u/darrenwin)\
**Post date:** [June 8, 2021, 8:43pm UTC](https://forum.juce.com/t/console-or-gui-at-the-same-time/46369/2 "2021-06-08T20:43:03Z")

</div>

in your Main.cpp initialise function, just case in there on your command line params. If you want to show a GUI, set your mainWindow variable (mainWindow.reset(…)), else do what you need to do headless.

---

<div class="post-metadata">

**Author:** ![yndurain](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yndurain/32/3261_2.png) [@yndurain](https://forum.juce.com/u/yndurain)\
**Post date:** [June 9, 2021, 8:52am UTC](https://forum.juce.com/t/console-or-gui-at-the-same-time/46369/3 "2021-06-09T08:52:42Z")

</div>

Thanks @darrenwin , I already do that. Something like

if (commandLine.isNotEmpty()) //exec command line app  
{  
doMyCalculations();  
}  
else //show gui  
{  
mMainWindow.reset(new MainWindow(getApplicationName()));  
}

The problem is that when it goes through the GUI option it also shows the console on the background. And I don’t want to see this.

In my preprocessor definitions I have:  
\_CONSOLE;\_CRT\_SECURE\_NO\_WARNINGS;WIN32;\_WINDOWS;

and if I remove \_CONSOLE; (which I’m not sure I want to do that as when no parameters I want (just) the console, then I get a link error

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/7f44d287afd1b9f2cdf9f72c99cf5beebe29e407.png)

Any other ideas?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [June 9, 2021, 10:48am UTC](https://forum.juce.com/t/console-or-gui-at-the-same-time/46369/4 "2021-06-09T10:48:36Z")

</div>

I would start a new project with the GUI Application template. That won’t have that \_CONSOLE and other console related settings in the build.

If it is run from the Explorer/double click, there are no arguments and you open the GUI.  
If it is run from the terminal and arguments are supplied, you simply don’t create a window like suggested before. All works as intended.  
The settings you have now are trying to open a terminal if not started from a terminal IIRC. But when you get cmd arguments, there is already a terminal, so no need for the \_CONSOLE switch.

Ignoring arguments from a shortcut for now…

HTH

---

<div class="post-metadata">

**Author:** ![yndurain](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yndurain/32/3261_2.png) [@yndurain](https://forum.juce.com/u/yndurain)\
**Post date:** [June 10, 2021, 9:56am UTC](https://forum.juce.com/t/console-or-gui-at-the-same-time/46369/5 "2021-06-10T09:56:03Z")

</div>

Thanks @daniel , that did the trick.

If anyone needs this is under Linker-\>System: SubSystem: Windows (SUBSYSTEM:WINDOWS)

My project was as “CONSOLE”

Thanks!
