Reputation: 93
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
Reputation: 29
The closest we can get is by clearing the terminal before code runner runs the code. To do that:
"code-runner.executorMap": {
"java": "cd $dir && javac $fileName && clear && java $fileNameWithoutExt"
}
Upvotes: 0
Reputation: 29
Install code runner extension
go to File> preferences > settings search for "Code-runner: Run In Terminal" and enable it to accept input from scanner.
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
Upvotes: 0
Reputation: 9481
There are some workarounds:
1.Add this in settings.json:
"terminal.integrated.enableFileLinks": false,
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:
3.Install the extension Code Runner and add the following code in settings.json:
"code-runner.clearPreviousOutput": true,
"code-runner.showExecutionMessage": false,
Upvotes: 1