Stop command prompt from opening when running compiled .exe - c++

When I build, compile and run my Visual Studio project, a command prompt also opens with the window. It does this with the compiled .exes as well as in the dev environment. Is there a way to stop the command prompt from opening for the compiled .exes?

You can switch the subsystem in the linker settings from "CONSOLE" to "WINDOWS", which will stop the OS from creating an initial console window for the process. It can still create one afterwards though, in which case you'd have to modify the code.

Try switching compilation mode to 'Release'. Change build target to another than console (depends on your current project, for example Win32 Application).

Related

How to let the c++ output in the vc code terminal

When I run a C++ program in vs code, it alway pops up a new window. Are there any ways to let the program output to the inner terminal (or output window) of vs code, instead of the annoying pop up window?
In VS-Code you configure the build/run in the tasks.json, and the debug in the launch.json (all configuration files go under ${workspaceFolder}/.vscode/).
You can set a keyboard shortcut for each task or for debug. For example my default build task is run with Ctrl+Shift+Band debug starts with F5. More info on how to set build/run/debug in VS-Code:
https://code.visualstudio.com/docs/languages/cpp
And as shingo mentioned depending on the externalConsole flag you can control if a new terminal window pops up or not.

How to view complete CMD execution command, including arguments and flags?

In Visual Studio, how can the run command for a console application be viewed?
Imagine a complex C++ application with a lot of startup flags and arguments.
It runs fine from the "Debug -> Start Without Debugging" option from the menu.
I would like to run the executable within a Command Prompt window, without starting Visual Studio. I try and run the executable, without success, like so:
./myProgram.exe
How can the command that VS uses to start the application--with all flags and arguments--be viewed?
If your app is running, Process Explorer shows complete command line. If your app is short lived, Process Monitor records what arguments were used to start it.

Running CLion on the System console (like Visual Studio)

I am trying to run a simple C++ program on CLion. The problem is that when I try to compile and run it, it shows the result in the application console. I want to run on the System console like the Visual Studio runs the output of the console apps. Is there a way of doing this. I use MINGW compiler.
You can use an external terminal, do these steps.
(top menu) run\ edit Configurations
tick 'run in external console'
Well, if anyone is still around wanting to open an external cmd window on run, there is a way to do it on Windows as well:
Go to Run > Edit Configurations
For the executable select C:\Windows\System32\cmd.exe
For program arguments use: /c "start cmd.exe #cmd /k "ProjectName.exe""
For working directory set the cmake debug (or release) folder
Save and select the profile from the dropdown right next to the run button
Note: In the third step /k can be replaced with /c to make the window close after the program is run (with /c its more like visual studio and with /k its more like code blocks)
I am not sure about Windows but in linux you can do it using this answer.
You might be able to change the gnome-terminal to cmd if you are using windows but you will probably need to change the "Program Arguments" too.
the above answer works fine in windows also. In working directory you can set this $CMakeCurrentBuildDir$
enter image description here

C++ disallow command prompt from displaying

Is there any thing I can do to make sure that the shell/command prompt does not show up when I run my C++ program, it is meant to be a background program? While it isn't a huge deal if it displays because it quickly closes, I would prefer it doesn't display at all. Program will run on windows xp/vista/7 OS
Configure your compiler or linker to mark your program as a GUI application.
Windows recognizes two main types of programs: GUI and console. If the EXE header is marked as a console program, then the OS creates a console window prior to executing it. Otherwise, it doesn't. This isn't something you can control at run time; you need to set it at link time. (You can call ShowWindow(GetConsoelWindow(), SW_HIDE) to try to control it at run time, but that doesn't prevent the window from flickering on and then off again. Plus, if your program is sharing the console with another program, like cmd.exe, then you'll have just hidden the user's command-prompt window!) Even if your program doesn't have any actual GUI, that's still the mode you need to avoid having a console window created for you.
If you're starting a new project in Visual Studio, select the "Win32 Console Application" option. If you already have a project, then in your project's configuration properties, find the "Subsystem" setting of the "Linker/System" section and set it to "Console." That makes the linker use the /subsystem:console option. If you're using Mingw, use the -Wl,--subsystem,windows option.
Sounds to me like you want to create a Windows service, not a command line utility. This is why services exist. Long running background tasks that require no user interaction. A simple example here.

Easy way to run command line programs C++ - Windows 7

I am trying to find an easier way to test my command line application. It has arguments so I run it from a command prompt. My process is this:
Build
Go to the output
Open command prompt
Change directory
Run it
There has to be an easier way not only to debug but to open a command prompt in the current folder.
Thank you for your time.
If you go to the project properties, Debugging settings, you can set the working directory and parameters. If you use the same parameters all of the time, you can enter those in on that screen as well. Then just F5 or Ctrl+F5 to run.
Set a breakpoint at the end of the code to keep it from going away after it is done.
See Debugging with command-line parameters in Visual Studio
Alternatively, you should be able to use a shell script (or Python os.system()) to automate some of those steps.
To open a command prompt in the current directory using explorer, you can shift+right click->Open Command Window Here. That will save a little time.
If you're using Visual Studio, pressing F5 will run the code in the debugger, and Ctrl+F5 will run the code normally. Just remember to include a cin.get() statement at the end or the terminal window will close before you can read the output.
Other IDEs should have similar functions. Check in the Run or Debug menu.
EDIT: Sorry, didn't see that you're asking about running it with arguments. In VS, in Project Properties there are the Debugging settings. Within that, there is a field called Command Arguments. These will get passed to the application when you run it from within VS.
In project properties under debugging you can set the command line arguments (and environment variables) when debugging,
There is an extension called PowerCommands for Visual Studio 2010 that can be installed from Tools -> Extension Manager. It includes a Open Containing Folder and Open Command Prompt functionality that gets added to your right-click menu in the Solution Explorer.