java - 代码在命令提示符中运行但不在 Eclipse 中运行

标签 java command-prompt bufferedreader readline runtime.exec

下面给出的代码是我尝试在 Eclipse 中运行的代码,当我尝试通过命令提示符运行命令时,它返回 stdInput.readLine() 作为 null,它成功运行我在做什么错了?

public class Recognize {
public String Recog(String name)
{   try {
    String command="java -cp .;C:\\mywork\\Speaker\\marf-0.3.0-devel-20070108-fat.jar SpeakerIdentApp --ident C:\\mywork\\Speaker\\testing-samples\\"+name+".wav";
        Process proc = Runtime.getRuntime().exec(command);
         BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
           BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
       name = "";   
       String s ;
       System.out.println(stdInput.readLine());
       // read the output from the command
      // System.out.println("Here is the standard output of the command:\n");
       while ((s=stdInput.readLine()) != null){
              // System.out.println(s);
               String recog = s;
            //   System.out.println(recog);
               String ex = stdInput.readLine();
            //   System.out.println(ex);
               String sb = stdInput.readLine();
             //  System.out.println(sb);
               if ( recog.equalsIgnoreCase(ex))
               {//System.out.println("ACCESS GRANTED");
                name = recog;
              // System.out.print(recog);
                }
               else if (ex.equalsIgnoreCase(sb))
               {//System.out.println("ACCESS GRANTED");
                name = ex;
               // System.out.println(ex);
                }
               else {//System.out.println("ACCESS DENIED");
                name = "";
       }

最佳答案

肯定是因为你没有设置eclipse默认路径,所以尝试根据你的需求设置eclipse默认路径

关于java - 代码在命令提示符中运行但不在 Eclipse 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15986146/

相关文章:

Java BufferedReader while循环越界异常

java - 无法使用 ArrayList<HashMap<String,?>>> 填充 listView

java - 如何在Python中检查Windows中 "start"命令启动的程序的输出?

java - 从命令提示符运行 JAR 文件时为什么会出现异常?

linux - 如何在获取find命令返回的结果后在while循环中复制文件?

java - 为什么我的字符串返回 "\ufffd\ufffdN a m e"

java - BufferedReader readLine() 方法花费了很多时间

java - 矩阵与浮点opencv android的乘法

java - 如何将 Sleuth 集成到 Spring Boot 1.5 中以在较新的 Spring Boot 2.2 中传播跟踪 ID?

java - 我们能得到的最接近 OO 软件设计中的概念和指导原则的明确列表是什么?