Search code examples
javacommand-promptbufferedreaderreadlineruntime.exec

code runs in command prompt but does not run in eclipse


The code given below is the code that i try to run in eclipse which returns stdInput.readLine() as null when i try to run the command through command prompt it runs successfully what am i doing wrong?

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 = "";
       }

Solution

  • it must be because eclipse default path is not set by you so try setting eclipse default path according to your requirement