Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS code shows print output in TERMINAL instead of OUTPUT

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.

enter image description here

like image 345
Parseval Avatar asked Jan 25 '23 23:01

Parseval


2 Answers

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:

enter image description here

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).

like image 27
Ewan Avatar answered Jan 27 '23 13:01

Ewan


{
    // 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.

Output in debug console

like image 168
tHeSiD Avatar answered Jan 27 '23 12:01

tHeSiD