Vscode-java-debug: Debugger cannot read input file contents

Created on 23 Sep 2019  路  3Comments  路  Source: microsoft/vscode-java-debug

[provide a description of the issue]
What I'd like to do is to read input file in java as stdin by using "args" command in launch.json.

Environment
  • Operating System: Windows 10
  • JDK version: OpenJDK 11.0.3
  • Visual Studio Code version: 1.37.1 and 1.38.1
  • Java extension version: 0.8.0
  • Java Debugger extension version: 0.21.0
Steps To Reproduce
  1. [step 1]
    Prepare the following files.
Main.java

```Java : Main.java
import java.util.*;
public class Main{
public static void main (String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
}
}


###### launch.json
```Json:launch.json
        {
            "type": "java",
            "name": "Debug (Launch) - Current File",
            "request": "launch",
            "mainClass": "${file}",
            "projectName": "java_project",
            "args": [
                "<",
                "src/stdin.txt"
            ],
            "console": "integratedTerminal"
        }
stdin.txt
121
  1. [step 2]
    F5 debug.

[attach a sample project reproducing the error]
[attach logs](https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#enable-logging)

Current Result

This configuration in Java Debugger v0.21.0 brings an NoSuchElementException. Main.java reads the input file stdin.txt, but no characters in that file.

Expected Result

Has no exceptions.

Additional Informations
  • Just changing the version to v0.20.0 solves this problem (some settings changed?).
  • The command in the internalTerminal java Main.java < src/stdin.txt does work well.

Thanks for reading.

bug terminal

Most helpful comment

Currently a workaround is to escape the special character < in launch.json manually.

  • If your terminal is cmd or powershell, please use ^< instead.
  • If your terminal is git bash, please use \^\< instead.

All 3 comments

In 0.21.0, we changed the default console to integratedTerminal, and introduced a launcher.bat to fix the encoding issue. Looks like the bat script eats the "< src/stdin.txt" args.

Currently a workaround is to escape the special character < in launch.json manually.

  • If your terminal is cmd or powershell, please use ^< instead.
  • If your terminal is git bash, please use \^\< instead.

Hello,
I have been facing the same doubt, could you please provide more detail on how is the call being made after the sucessfull modification? So I can try to understand what is my mistake?
For instance mine is
c: && cd c:\Users\UserName\Documents\01_UFU_local\07_algoritmo\2021_1\test\testing && cmd /C "c:\Users\UserName.vscode\extensions\vscjava.vscode-java-debug-0.32.0\scripts\launcher.bat "C:\Program Files\Java\jdk-15.0.2\bin\java.exe" -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:59610 --enable-preview -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 @C:\Users\UserName\AppData\Local\Temp\cp_ap8myj75dr7wcc3936mshu66a.argfile Main < src/stdin.txt "
Many thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radu-ion picture radu-ion  路  5Comments

gcbartlett picture gcbartlett  路  3Comments

ivenxu picture ivenxu  路  8Comments

TheSinding picture TheSinding  路  6Comments

isidorn picture isidorn  路  4Comments