Runtime Environment + Linux + the "find" command
Hi everybody,
I want to write a small program which makes it easy for me to use the [url=http://www.linux.com/article.pl?sid=06/06/28/1541237]find command[/url] with Linux. I have experience with Java but I have never used the runtime environment before. I am not sure how to best execute the "find" command. I tried this:
publicstaticvoid main(String[] args)
{
String command ="find -name \"*\"";
execute(command);
}
privatestaticvoid execute(String p_command)
{
// Show the executed command.
System.out.println(p_command);
// Get the runtime object and handle the command.
Runtime rt = Runtime.getRuntime();
try
{
// Execute the command.
Process proc = rt.exec(p_command);
// Show the output of the command.
InputStream stdin = proc.getInputStream();
InputStreamReader isr =new InputStreamReader(stdin);
BufferedReader br =new BufferedReader(isr);
String line =null;
System.out.println("<OUTPUT>");
while ( (line = br.readLine()) !=null) System.out.println(line);
System.out.println("</OUTPUT>");
// Show the exit value of the process.
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
}
catch (Exception e)
{
System.out.println("Could not excecute: " + p_command);
}
}
This piece of code returns this:
find -name"*"
<OUTPUT>
</OUTPUT>
Process exitValue: 0
This is not correct, because it should return something like this:
[jethro@laptop FindNix]$ find -name"*"
.
./nbproject
./nbproject/project.xml
./nbproject/project.properties
./nbproject/private
./nbproject/private/private.properties
./nbproject/build-impl.xml
./nbproject/genfiles.properties
./build.xml
./src
./src/findnix
./src/findnix/Main.java
./test
./manifest.mf
./build
./build/classes
./build/classes/findnix
./build/classes/findnix/Main.class
Does anybody know what I am doing wrong?
Best regards,
Jethro Borsje

