LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2004, 01:21 PM   #1
ushradha
LQ Newbie
 
Registered: Oct 2004
Posts: 8

Rep: Reputation: 0
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
 
Old 11-03-2004, 11:31 PM   #2
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
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);
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java problem chidomen Linux - Newbie 3 01-14-2005 08:27 PM
Java Problem...again theguitarsquall Mandriva 8 01-08-2005 12:44 PM
Java Problem anirudh Programming 6 10-27-2004 03:42 PM
Java problem CragStar Programming 11 03-11-2004 10:02 AM
Java problem please help bwaynej2002 Linux - Software 2 02-06-2004 08:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration