Crazy Java Problem Involving AIX
(hctunx04)/home/cad8278-->java -version
java version"1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1)
Classic VM (build 1.4.1, J2RE 1.4.1 IBM AIX build ca1411sr2b-20040520 (JIT enabled: jitc))
Okay. what I'm trying to accomplish:
I'm trying to run a command in unix, and chew on that data in java. Simple, right?
The problem I'm running into:
When I'm reading in the inputStream, I'm only getting parts of the data:
This is the output I get when running the command in unix:
(hctunx04)/home/cad8278-->ls | grep txt
24011C.rmd07015.txt.0160246
24030C.rmd07015.txt.0160246
output.txt
output2.txt
output3.txt
possibleDays.txt
test.txt
tree.txt
treedata.txt
This is what prints out when I run my code:
24030C.rmd07015.txt.0160246
output2.txt
possibleDays.txt
tree.txt
null
Here is the code that I'm running:
Runtime rtime = Runtime.getRuntime();
Process child = rtime.exec(new String[]{"/bin/bsh","-c", getCommand()});
//set up the InputStream reader
InputStreamReader isr =new InputStreamReader(child.getInputStream());
BufferedReader br =new BufferedReader(isr);
while (br.readLine()!=null){
sb.append(br.readLine() +"\n");
}
Okay, so I'm getting intermittent data... and a null... odd.
If I change the code to this:
Runtime rtime = Runtime.getRuntime();
Process child = rtime.exec(new String[]{"/bin/bsh","-c", getCommand()});
//set up the InputStream reader
InputStreamReader isr =new InputStreamReader(child.getInputStream());
BufferedReader br =new BufferedReader(isr);
for(int i = 0; i < 30; i++)
{
sb.append(br.readLine() +"\n");
}
Then my output is:
24011C.rmd07015.txt.0160246
24030C.rmd07015.txt.0160246
output.txt
output2.txt
output3.txt
possibleDays.txt
test.txt
tree.txt
treedata.txt
null
null
null
[.. many nulls]
null
null
I get all of data... but I'm not sure how to stop my loop.
BTW, if I change my for loop to:
for(int i = 0; i < 30; i++)
{
if(br.readLine()!=null)
sb.append(br.readLine() +"\n");
}
I get the same results as the while loop.
Any advice would be much, much appreciative.
--Adam
Message was edited by:
TundraWolf_

