【问题标题】:code runs in command prompt but does not run in eclipse代码在命令提示符下运行,但不在 eclipse 中运行
【发布时间】:2013-04-13 09:07:45
【问题描述】:

下面给出的代码是我尝试在 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 = "";
       }

【问题讨论】:

  • 尝试在类“SpeakerIdentApp”的类路径中指定目录位置或 JAR 文件名
  • 在 Eclipse 或我的系统中??
  • 行内 java -cp .;C:\\mywork\\Speaker\\m...
  • 我试过了,但是当我在命令提示符中尝试它时没有用,它显示 noclasdeffounfexception
  • 你能打印你在 stdError 流上得到的东西吗?

标签: java command-prompt bufferedreader readline runtime.exec


【解决方案1】:

一定是因为eclipse默认路径不是你设置的所以尝试根据你的要求设置eclipse默认路径

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 2019-05-28
    • 2020-12-16
    • 2023-03-25
    相关资源
    最近更新 更多