How to stop console from closing on exit? [duplicate] - visual-studio

This question already has answers here:
Preventing console window from closing on Visual Studio C/C++ Console application
(24 answers)
Closed 8 years ago.
I'm using Visual Studio 2010 and Windows 7 x64
The command prompt closes after exit, even though I used "Start without debug". Is there a setting somewhere that I can use?

You can simply press Ctrl+F5 instead of F5 to run the built code. Then it will prompt you to press any key to continue. Or you can use this line -> system("pause"); at the end of the code to make it wait until you press any key.
However, if you use the above line, system("pause"); and press Ctrl+F5 to run, it will prompt you twice!

Yes, in VS2010 they changed this behavior somewhy.
Open your project and navigate to the following menu: Project -> YourProjectName Properties -> Configuration Properties -> Linker -> System. There in the field SubSystem use the drop-down to select Console (/SUBSYSTEM:CONSOLE) and apply the change.
"Start without debugging" should do the right thing now.
Or, if you write in C++ or in C, put
system("pause");
at the end of your program, then you'll get "Press any key to continue..." even when running in debug mode.

What about Console.Readline();?

Add a Console.ReadKey call to your program to force it to wait for you to press a key before exiting.

You could open a command prompt, CD to the Debug or Release folder, and type the name of your exe. When I suggest this to people they think it is a lot of work, but here are the bare minimum clicks and keystrokes for this:
in Visual Studio, right click your project in Solution Explorer or the tab with the file name if you have a file in the solution open, and choose Open Containing Folder or Open in Windows Explorer
in the resulting Windows Explorer window, double-click your way to the folder with the exe
Shift-right-click in the background of the explorer window and choose Open Commmand Window here
type the first letter of your executable and press tab until the full name appears
press enter
I think that's 14 keystrokes and clicks (counting shift-right-click as two for example) which really isn't much. Once you have the command prompt, of course, running it again is just up-arrow, enter.

Related

Vscode Debug Streamlining: How To HotKey Current File To Run in Visual Studio Code Terminal?

I'm new to Vscode. In the old IDE I could hit a hotkey and the current file with window focus would execute in a terminal window.
I can't seem to replicate in Vscode?
CTR+F5, doesn't give me a terminal window. Selecting "Run Without Debugging" from the run menu drop down doesn't seem to do anything either.
Right now I'm having to open a terminal window, save the script, and then run it in terminal seperately.
Surely there is an automated way to save, then run the script right in Vscode, and show me the terminal output?

How to prevent the Output window in VS from disappearing?

when I press Start to run my application in VS 2017 Community my Output window disappears. (I use it for i.e. Debug.WriteLine().) How to prevent this?
P.S.
The output window I`m refering to (not the command line window!):
The output window
Thanks
~Julius
After starting your application (debug mode), click View > Output (Ctrl + Alt + O) to show the output window. Stop your application and restart Visual Studio. Next time you run your application the output window should be visible automatically because Visual Studio remembers your opened windows in debug mode.
Prevent it from autohiding using the 'Auto hide' icon in the right top corner (center of the three) of the Output window. That way it will stay docked.
You can make it a docked tab before running your program
On Menu Bar:
Tools -> Options
A Pop-up window appears:
Debugging -> General -> Automatically close the console(scroll down to last)
Check the box and close
It applied to projects for visual studio.
Press Any Key to Continue...

Waiting for second key of chord

I have assigned the keyboard shortcut Ctrl+E to a command. But when I click Ctrl+E, the status bar says Ctrl+E was pressed. Waiting for the second key of the chord...".
If I hit the Esc key, I get "The key combination (Ctrl+E, Esc) is not a command."
How do I activate the command that has been assigned to Ctrl+E?
I know that this is the same as the question How do you stop Visual Studio from waiting for the second part of a shortcut-combination? . But the answer given there (hit Esc) does not work for me.
The selected answer is wrong in stating you cannot use Ctrl+E by itself (at least for Visual Studio 2013).
For those who come from a Mac or other OS background where Ctrl+E takes you to the end of the current line (the End key shortcut by default in VS), this is a really frustrating limitation when switching environments.
I found that in Visual Studio 2013 at least, you can remove all the shortcuts that use the Ctrl+E chord (none of which I will ever use) and set the Edit.LineEnd command to Ctrl+E. It just takes a few minutes tracking down the chords to remove (most of them are under the workspace designer).
To see which commands are using your keyboard shortcut at the moment, enter it
in the "Press shortcut keys:" edit box. Make sure you don't accidentally click "Assign".
In the dropdown box "Shortcut currently used by:" you can browse
through and manually remove all commands that
currently occupy your desired shortcut combination.
Key chords are a keyboard shortcut feature of Visual Studio. They consist of a sequence of key presses like (Ctrl+K, Ctrl+C) for comment code or (Ctrl+K, Ctrl+U) for uncomment code.
They are activated by the user pressing one Ctrl+key combination, then another Ctrl+key combo. For example Ctrl+K, Ctrl+C on my install of Visual Studio is used for commenting selected text.
In your case, Ctrl+E is a common chord starter and is used by many chords. For example Ctrl+E, Ctrl+W = Toggle Word Wrap and Ctrl+E, Ctrl+X = Workspace Designer.ExpandAll.
Depending on which developer setting you've chosen for the IDE, Visual Studio might have Ctrl+E mapped to other chords. In that situation, you cannot use Ctrl+E by itself for a keyboard shortcut
If this is the case, you can create your own chord, Ctrl+E, Ctrl+D is not in use on my install of Visual Studio 2012.
Edit:
Also if you remove all key chords that start with (Ctrl+E) then it can work as a non-chord shortcut.
And your question is not the same as the other question. In that question, the OP has started the chord process (Ctrl+E) and wants to cancel Visual Studio from waiting for the 2nd chord key.
I came to this question because I had the same problem as the OP, but in the Integrated Terminal of Visual Studio Code (not Visual Studio).
My problem:
I couldn't stop the node server by doing Ctrl+C, because my VS Code was waiting for the "second key of chord"...
I fixed it in the user settings, by unchecking the Allow Chords checkbox.
I answered the more suitable question for me here.
I have had the same issue with my "<" [backquote] key and wasn't able to find the right keybinding in the normal settings. Allow chords wouldn't do anything either.
This is for anyone, who isn't able to reasign the key in the default keybindings:
Find the User settings in your terminal.
Windows %APPDATA%\Code\User\
macOS $HOME/Library/Application Support/Code/User/
Linux $HOME/.config/Code/User/
Open the keybindings.json file
look for all chords that you would like gone.
(Obviously) remove/alter them
I hope I could help some of you!
You can disable it only for the integrated VSCode terminal by adding the following to your setttings.json file:
{
...
// Disable chords for terminal usage
"terminal.integrated.allowChords": false
...
}
Go to Tools -> Options.
A window will open up, In that Environment -> Keyboard -> Keyboard
And Just Press the Reset button on the right.
Screenshot
Do
ctrl+ E
then
ctrl + V
More info here:

Why does VS2012 think my command keys are me attempting to edit code?

E.g. when I hit Ctrl-D, I for an immediate window, I have to move my mouse pointer out of the code window, or I get told I'm not allowed to edit code while it is running. I've only recently encountered this.
Not knowing how your Visual Studio is setup, I cannot say. However, try doing the following:
Open Visual Studio 2012 then go to Tools > Options...
In the Options menu, go to Environment > Keyboard.
From there, click inside the "Press shortcut keys:" input box and, using your keyboard, type CTRL + D. Once you do that, it will show you what command is currently using that shortcut.
Finally, type in the command name in the "Show commands containing:" input box. Click the command name from the list below, then click 'Remove'.
Hope this is what you are looking for! Let me know if you have any other questions!

Visual Studio 2010 External Tools - How to automatically attach a debugger to the tool when it is started?

I am writing a DirectShow filter, and when I want to debug it I must:
Run GraphStudio (or GraphEdit) from Tools (I added it to external tools)
Click on Debug > Attach to process...
Search for "GraphStudio" in the process list
Double click on it...
Can this be automated in VisualStudio 2010? Like, I want to select an external tool from Tools menu, and get the debugger automatically attached to it...?
This isn't perfect but it saves you a couple of steps.
In Solution Explorer, right click on your project and select properties. Now select the debugging tab. Change the Command line from $(TargetPath) to GraphStudio.exe (or whatever your process name is). Change the Attach line from No to Yes. Click on OK.
Now your steps are
Run GraphStudio from Tools
Press F5 (or Start | Debug).
The debugger will attach to the process identified by the Command line entry. If there is more than one GraphStudio running it will attach to all of them.
If you don't need to run GraphStudio as an external tool then you can simplify things even further by changing the Attach line back to No and changing the Command line to hold the full pathname of the tool you want to run. If needed you can also set working directory and Command Arguments (switches etc.)
Now just start a debugging session by pressing F5. the debugger will run Graphstudio for you and will attach to that copy only.
You can use gflags or IFEO to do this. I mention it in this answer.

Resources