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.
Related
I know i can use "system pause" or "getchar" to make the screen doesn't disappear immeadiately when i use VSCode to execute my c/c++ program,but it's really troublesome.I want to know if i could let the program pause automaticly just like
VS and other IDE.
VSCode have the Intergrated terminal (Ctrl + `), you can run and see console output there.
Even in Visual Studio C++, if you do not set break point, the console app will terminate and disappear when reach return 0 in main.
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).
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.
I am using Eclipse with C++. When I run the program, I get the following message in my Console window:
**** Build of configuration Debug for project Disks Repulsion ****
**** Internal Builder is used for build ****
Nothing to build for Disks Repulsion
I makes changes to the program and run it again, and this time I get following message:
**** Build of configuration Debug for project Disks Repulsion ****
**** Internal Builder is used for build ****
g++ -oDisksRepulsion.exe DisksRepulsion.o -lopengl32 -lglu32 -lglut32
C:\MinGW\bin..\lib\gcc\mingw32\3.4.5........\mingw32\bin\ld.exe: cannot open output file DisksRepulsion.exe: Permission denied
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 103 ms.
When I first ran the program, it started my program (I can see it running in my Window Task Manager), but there is no output being sent to the console.
After making changes to my program, the program is still running in the background, so I get the "Permission denied" error, when I try to run the program. I can make the error go away by ending the instances via task manager. However, when I run the program, I still don't see any output being sent to the console.
Yesterday, I was able to see the output in my console, but don't know why I cannot see it today. Also, when I saw my output, the cursor's focus did not change from the code to the console. I dislike having to do it manually.
I also don't like that when I make changes to my program, and run it again, that the program is not automatically terminated on its own.
I have used VC++ and I prefer the window Dos for output. So, I wanted to know if there is anyway in Eclipse to send the output to Windows Command Prompt, since I know that the instance of the .exe is really gone when I close the program. It automatically gets cursor's focus. I will also be able to get some output.
I installed MinGW with MaSYS or something, to compile the program.
It sounds like your application isn't terminating on its own and you didn't build in any sort of interface that would allow you to kill the program. This sounds like a bug in your code and not an Eclipse issue. If issuing a Ctrl+C in the console won't kill your program, then look into coding something that will let you kill your app with keystroke or input sequence.
If you want to run your app in a command console, then open a normal command console, browse to the folder containing your project, and run the compiled executable from the console instead of doing it through the Eclipse interface.
A simple solution, which I've been using for ages now, is opening a command prompt yourself and running the executable manually. An advantage of this method is that you can set your "DOS" window's size to anything you want. (Right now I'm using a 120x50 window with 8192 lines of scrollback buffer.) Another one is that you will never lose your console output; in fact, you'll be able to see outputs from past runs. (8192 lines is A LOT unless you're printf-debugging a tight loop.)
An alternative to terminating your program from the taskbar is using the red icons on the top right corner of the Eclipse "Console" window.
Is your program's entrypoint main() or WinMain()? There may also be a setting/link option for the "subsystem," console or Windows I think they're called in Visual Studio.
Anyway, if your program is starting up via WinMain, the expectation is that you'll have a Windows form of some sort through which the user can control the program. If you use main(), then your program should automatically trigger the opening of a console window.
Look up AllocConsole() on MSDN (or google it) if you are using WinMain() intentionally and want a console window to also open up. There's some trickery also available via google search that can hook stdout to this console, but at this time I don't remember what it is. (You basically redirect the stdout handle to your new console.)
Good luck.
Using VS .NET 2003. Would like to run the .exe from outside the IDE (i.e. command prompt or double clicking .exe icon in windows) However, still want break points to hit in the IDE.
How do I set this up?
(Running from outside IDE but IDE seeing it as run from "Debug" -> "Start")
Thanks.
On the Debug menu, choose the "Attach to process" option to attach a debugger to your externally-running application.
Visual Studio enables Just In Time Debugging by default. If you haven't turned it off you can call DebugBreak() and you will get a popup allowing you to attach a debugger. If you don't attach a debugger then the program will exit, so you could try wrapping the DebugBreak call in a MessageBox or some other conditional code based on an environment variable or config item.
Since it is C the call to DebugBreak() is correct - this will give you a nasty error dialog (different look depending on the OS), which should have a 'Debug' option. If you click this you should get a dialog to select one of the installed debuggers (VS.NET shoud be among them). Selecting it should bring you to the DebugBreak() line. However this can fail if the debugger can not find the pdb files for your app - in that case you will just get the disassembly view and no source code view.
You can also use WinDBG and the 'Open executable option' - again it will need the pdb files to yield anything useful.