LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   java Inputstraemreader problem (https://www.linuxquestions.org/questions/programming-9/java-inputstraemreader-problem-250292/)

ushradha 11-02-2004 01:21 PM

java Inputstraemreader problem
 
Hi ,
I am trying to exceute a command in java and try to read the output line by line.
Sting string1=new String("ls" , "-l" ,filenam);
Process p=Runtime.getRuntime().exc(str1,null,dir)
BufferReader line_ls=new BufferedReader(newInputStreamReader(p.getInputStream());
System.out.println(line_ls.ready());


The ouput is false

this means the input stream is blank.But since the program is not throwing io exception the command is exceuting.

I dont understand why the inputstream is blank.
Please advice

german 11-03-2004 11:31 PM

use the String[] argument constructor:

Code:

String[] s = new String[] { "ls", "-l", "/home/me"};

Process p = Runtime.getRuntime().exec(s);

InputStream in = p.getInputStream();

int n;

while((n = in.read()) != -1) {
  System.out.write(n);
}



All times are GMT -5. The time now is 08:12 AM.