Reputation: 813
I'm trying to set up VS code for java programming, and I'm kind of done. However one thing in particular bothers me. When I for example run the code below I get the output in the TERMINAL tab along with a lot of other junk that I don't want to see. How can I change it so that the only output is "Testing..." in the console?
public class Hello{
public static void main(String[] args){
System.out.println("Testing...");
}
}
The output after I run the code is shown in the figure below. Even if I click on the other tabs, they are empty and even if I remove/hide the terminal tab, each time I re-run the code it pops up regardless.
Upvotes: 14
Views: 125847
Reputation: 21
I had the same issue. It's is very simple and you don't need to alter any preferences.
1)Just install code runner extension. 2)Restart vscode. 3)And run as code.
Upvotes: 0
Reputation: 1
In addition to above and after installing Code Runner, check if the keyboard shortcut you are using to run the code is NOT assigned to 'Python: Run Selection/ Line in Python Terminal'. Else each time you run the code thinking it will 'Run code', you are actually asking VS code to display all results in Python terminal instead of Output window. you can find the keyboard shortcuts under File-->Preferences.
Upvotes: 0
Reputation: 19
I think I have a better solution than the other answers. Just copy-paste the code below:
{
"workbench.colorTheme": "Solarized Dark",
"editor.mouseWheelZoom": true,
"editor.fontSize": 18,
"git.enableSmartCommit": true,
"code-runner.clearPreviousOutput": false,
"editor.snippetSuggestions": "top",
"window.zoomLevel":0,
"workbench.startupEditor": "newUntitledFile",
"code-runner.runInTerminal": false,
"code-runner.runInOutput": true,
"code-runner.saveFileBeforeRun":true,
"type": "c",
"name": "Debug (Launch) - Current File",
"request": "launch",
"args": "",
"console": "internalConsole",
"mainClass": "${file}",
"code-runner.ignoreSelection": true,
"terminal.integrated.tabs.enabled": true,
"json.schemas": [
],
"launch": {
"configurations": [],
"compounds": []
}
}
Go to File > Preference > Search json.setting > setting.json edit and simply paste it there.
"code-runner.runInTerminal": false,
"code-runner.runInOutput": true,
Check these two especially, after doing everything, you will get your output at "output".
Upvotes: 1
Reputation: 39
I have an easy solution for that! With this you can see results in output tab instead of terminal.
Follow these steps in vscode:
Use the same method above but by checking the box for viewing the results in terminal!
Upvotes: 2
Reputation: 109
I found an even easier answer to this problem thanks to the tHeSiD's answer. To solve it and achieve the same result as tHeSiD, you can do it in the vsCode setting config user interface (also this approach will ensure this new setting will work for all other java projects).
To go to the VsCode setting ui, open vscode, then on top right go to file -> preference -> setting. Then once you are there, to apply the new setting, search launch.json in the search settings box and then scroll down and change the setting to this:
Afterward, if you go back to your java program and press f5, your "Hello World" should show up nice and clear in the Debug Console (It should work as I have tested it, but if it doesn't work, try relaunching vsCode).
Upvotes: 7
Reputation: 5333
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"args": "",
"console": "internalConsole",
"mainClass": "${file}"
},
]
}
Add this to your launch.json
file. The important option for you here is "console": "internalConsole",
This will output everything to the Debug Console tab and not terminal. And it will look clean like this.
Upvotes: 13