简体   繁体   English

Java扫描仪无法在终端中工作

[英]java scanner not working in terminal

I have tried this on a Mac terminal and a Linux Mint terminal as well as Windows via a cmd terminal (on two different machines). 我已经在Mac终端和Linux Mint终端以及Windows上通过cmd终端(在两台不同的计算机上)尝试过此操作。 I am running the test through a build.xml file and I am using ant 1.8.2 and Java 1.6. 我正在通过build.xml文件运行测试,并且正在使用ant 1.8.2和Java 1.6。 It just hangs after I type in the input. 输入我的内容后,它就会挂起。 The exact same code works from within eclipse or by compiling and running manually (ie javac.. and then java...). 完全相同的代码可以在eclipse中运行,也可以通过手动编译并运行(即javac ..然后是java ...)来运行。 Any help would be appreciated.. 任何帮助,将不胜感激..

import java.util.Scanner;

public class ScannerTest {

    public static void main (String [] args){

        System.err.println("Enter Something...");
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        System.err.println("Entered: " + s);
    }
}

Try running your project with an older version of ant. 尝试使用较旧版本的ant运行项目。 There seems to be a bug(50960) already filed for a similar problem. 似乎已经有一个Bug(50960)针对类似问题提交了。 This is fixed in 1.8.3. 此问题已在1.8.3中修复。 Check the following links: 检查以下链接:

http://ant.1045680.n5.nabble.com/bug-in-ant-1-8-2-read-on-System-in-hangs-for-forked-java-task-td4258253.html http://ant.1045680.n5.nabble.com/bug-in-ant-1-8-2-read-on-System-in-hangs-for-forked-java-task-td4258253.html

https://issues.apache.org/bugzilla/show_bug.cgi?id=50960 https://issues.apache.org/bugzilla/show_bug.cgi?id=50960

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM