A much needed feature, especially for beginners learning to program, as many programming exercises require to print the output. Yet in this version of this extension the console closes as soon as the program finishes execution.
You can work around this by adding a cin >> to the end of your program so it waits for input before exiting.
@KristupasSavickas We call gdb to turn on/off the console. when debugging ends, gdb exits and since the console is a child process, it shuts down. We don't have control over it the way it is implemented now.
Adding as a feature request.
I recently went into a similar situation that needs this feature. And In my case, I am not able to manually add cin or getc since the target application raises an exception even before stepping into the main function. Hope this feature could be implemented soon so that I don't have to switch the environment to check the exception.
@lioujheyu To help you, you can enable logging in your launch.json. if you enable engineLogging, all the additional gdb information will be shown to you.
Thanks, @pieandcakes. This is quite handy :)
Without this feature, unable to see the output of my program
When debugging with gdb, it is gdb that launches and controls the terminal. Since we don't control the terminal, we don't have a way to keep it open. I have marked this as a feature request because if we get some suggestions on how to fix it we can revisit it but as of now, there isn't a fix planned.
You can add a breakpoint at the last line and hopefully that will stop the debugging so you can view your output.
I think if you can call "pause" command once the gdb exits would solve the issue. Also, when I did some investigation on Code::Blocks I found that they run the file as a child of cb_console_runner.exe and after the program gets terminated it prints the return value of the program as well as how long the program run for.
These feature would be nett as I mainly use C++ for ICPC and problem solving in general.
@KristupasSavickas We call gdb to turn on/off the console. when debugging ends, gdb exits and since the console is a child process, it shuts down. We don't have control over it the way it is implemented now.
Adding as a feature request.
Is this true? Looking at the terminal output before debugging I see
arch -arch x86_64 '/Users/maxcoplan/.vscode-insiders/extensions/ms-vscode.cpptools-0.25.1/debugAdapters/lldb/bin/lldb-launcher' --unix-socket=/tmp/fWQ1kx --arch=x86_64 --working-dir '/Users/maxcoplan/Documents/workspace/C' --disable-aslr -- '/Users/maxcoplan/Documents/workspace/C/hello' ; echo Process exited with status $? ; exit
Clearly the last command is exit. Wouldn't simply removing the exit at the end fix this?
@vegerot we aren't sending that command string. I suspect that might be VSCode.
Or it could be macOS. Given that whenever you open a binary executable from Finder (for example), it will also append ; exit; to it
@KristupasSavickas @pieandcakes @kurienmathew another option is to go to Terminal Preferences>Profiles>[default profile]>Shell>When the shell exits: and change it to "Don't close the window".
My preferred solution would be deleting the appended ; exit;, but this is a viable workaround
@vegerot how do I find this option in Windows?
🤷♂️
Does VSCode for Windows use cmd as its external editor?
https://www.itechtics.com/3-ways-to-prevent-command-prompt-from-closing-after-running-commands/
https://www.google.com/search?client=safari&rls=en&q=windows+cmd+don%27t+close+window&ie=UTF-8&oe=UTF-8
@vegerot
🤷♂️
Does VSCode for Windows use cmd as its external editor?
https://www.itechtics.com/3-ways-to-prevent-command-prompt-from-closing-after-running-commands/
https://www.google.com/search?client=safari&rls=en&q=windows+cmd+don%27t+close+window&ie=UTF-8&oe=UTF-8
What is a batch file I am new to coding and I just want to be able to see what my program does when I run it in vs code.
"What is a batch file?" Um, I don't really use Windows that much. I think it's like a shell script, if you know what that is. I'd recommend Googling it or asking someone. There are a couple of streamers on Twitch that could help you, if you'd like recommendations
You can kinda bypass the issue by writing,
system("pause")
at the very end of your main function. That works for me like a charm...
This issue has been closed automatically because it's labeled as 'external'.
Most helpful comment
@KristupasSavickas We call gdb to turn on/off the console. when debugging ends, gdb exits and since the console is a child process, it shuts down. We don't have control over it the way it is implemented now.
Adding as a feature request.