saga
saga

Reputation: 93

How to hide unwanted log messages on Visual Studio Code, running Java code

I am using Visual Studio Code to write Java programs. Everything works fine except that I always get unwanted messages when I run the code. For example, I created a very simple and basic Java project that contains a App.java file (in the src folder, default package):

public class App {
    public static void main(String[] args) throws Exception {
        System.out.println("Hello, World!");
    }
}

I have installed the extensions Java Test Runner and Debugger for Java. If I press "Run", I get:

PS C:\Users\Light\Documents\J\JVsc>  cd 'c:\Users\Light\Documents\J\JVsc'; & 'c:\Users\Light\.vscode\extensions\vscjava.vsco\extensions\vscjava.vscode-java-debug-0.28.0\scripts\launcher.bat' 'C:\Program Files\Java\jdk-11.0.1\bin\javaTF-8' '-cp' 'C:\Users\Ri.exe' '-Dfile.encoding=UTF-8' '-cp' 'C:\Users\Light\AppData\Roaming\Code\User\workspaceStorage\67e3f4593863e5815\bin' 'App'       7c280b6c994f0132b01b2\redhat.java\jdt_ws\JVsc_623e5815\bin' 'App'
Hello, World!

This is very bad to see, and I have to record the video for school purposes, and I don't want these messages to appear. I dont' even know if this is a debugger issue or not.

It seems that VSC calls "CD command" before running the program. I have tried to change the launch.json setting "console": "internalConsole" but it does not solve the problem, what it happens with this setting set up this way is that NO output at all is shown.

If I digit "cd src" then MANUALLY call "java App.java" it prints Hello World without that message, but obviously I don't want to manually type the compile and run commands.

Upvotes: 3

Views: 5391

Answers (3)

mj balcueva
mj balcueva

Reputation: 29

The closest we can get is by clearing the terminal before code runner runs the code. To do that:

  1. Use the Code Runner extension
  2. In your settings.json file, change the java value in code-runner.executor map so that it'll look like this:
"code-runner.executorMap": {
"java": "cd $dir && javac $fileName && clear && java $fileNameWithoutExt"
}

some screen shots:

  1. code runner not running
  2. just hit the run code button
  3. cleared console
  4. answered questions
  5. final output after everything

Upvotes: 0

Florian
Florian

Reputation: 29

enter image description here

  1. Install code runner extension

  2. go to File> preferences > settings search for "Code-runner: Run In Terminal" and enable it to accept input from scanner.

  3. go to File> preferences > settings, then search for "Executor Map" > click edit in settings.json and add the following modification corresponding to the programming language, java for example:

Java : "function prompt{ \">>\"} && clear && tput setaf 6 && cd $dir && javac $fileName && java $fileNameWithoutExt && echo `n && tput setaf 5",

you can check my videos for detailed explanation

https://youtu.be/WM5iW8SyGpk

https://youtu.be/yq8j3AsEOL0

Upvotes: 0

Molly Wang-MSFT
Molly Wang-MSFT

Reputation: 9481

There are some workarounds:

1.Add this in settings.json:

"terminal.integrated.enableFileLinks": false,

enter image description here which will show less scripts before output in integrated terminal.

2.Set "console": "externalTerminal" in launch.json, you'll get a external console and no scripts displayed befor the real output:

enter image description here

3.Install the extension Code Runner and add the following code in settings.json:

"code-runner.clearPreviousOutput": true,
"code-runner.showExecutionMessage": false,

enter image description here

Upvotes: 1

Related Questions