-2
import java.io.File;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.io.*;
 import java.io.InputStream;
 class pbdemo {

     static public void main(String[] args) throws Exception {
         String s;
         try {
             ProcessBuilder pb = new ProcessBuilder("cmd", "/f", "dir");
             pb.directory(new File("F:\\WINDOWS"));
             pb.start();
             BufferedReader br = new BufferedReader(new InputStreamReader(pb.getInputStream()));

             while ((s = br.readLine()) != null)
             System.out.println(s);

         } catch (Exception e) {
             System.out.println("sorry" + e);
         }
     }
 }

what is the problem in

BufferedReader br=new BufferedReader(new InputStreamReader(pb.getInputStream()));

I get cannot find symbol error.

Iswanto San
  • 18,263
  • 13
  • 58
  • 79
  • 2
    How about cut and paste the actual error message. It should tell you which of the 3 possibilities on that one line can't be found. – John3136 Mar 08 '13 at 02:26
  • seem duplicate : http://stackoverflow.com/questions/15286042/im-not-getting-any-output-and-probably-the-machine-hangs-with-the-code – Iswanto San Mar 08 '13 at 03:43

2 Answers2

0

You are trying to get an InputStream from a ProcessBuilder and that's wrong.

ProcessBuilder.start() returns a Process object, and that's the one who has a getInputStream() method.

Try switching that line for this one.

BufferedReader br=new BufferedReader(new InputStreamReader(pb.start().getInputStream()));

Or

Process pro = pb.start();
BufferedReader br=new BufferedReader(new InputStreamReader(pro.getInputStream()));
Iswanto San
  • 18,263
  • 13
  • 58
  • 79
0

Simple answer.

ProcessBuilder don't have getInputStream method.

See this: ProcessBuilder

You can use:

BufferedReader br=new BufferedReader(new InputStreamReader(pb.start().getInputStream()));
Iswanto San
  • 18,263
  • 13
  • 58
  • 79