getRuntime().exec problem under Linux

Here's a piece of code under Mandrake.

Process p;

try

{

p=Runtime.getRuntime().exec("/usr/local/WordNet-3.0/bin/./wn " + englishword +" -hypen > /home/istvan/wordnet/Kimenetek/ki.txt");//"englishword" is a String

//p=Runtime.getRuntime().exec("ls");

try{p.waitFor();}

catch (InterruptedException ex1){System.out.println(ex1.getMessage());}

System.out.println(p.getInputStream().toString());// > "java.io.BufferedInputStream@1bcc0bc"

System.out.println(p.getErrorStream().toString());// > "java.io.FileInputStream@111a3a4"

}

catch (IOException ex){System.out.println(ex.getMessage());}

It does absolutely nothing, doesn't create the desired "ki.txt" file, although from the command line works just fine. In fact, even at the simple "ls" command gives the message mentioned in the code as a comment.

Can somebody help me? Thanks in advance.

[1461 byte] By [tootles564a] at [2007-11-26 15:47:21]
# 1

There are several problems.

First of all, the "command > somefile" syntax is interpreted by

the shell on Linux. But exec does not load the shell by default.

So the redirection does not work.

Secondly, you should not execute the program as is,

and then read its output using "getInputStream()" afterwards.

There is buffer overflow and data starvation issues.

See this excellent tutorial for how to create separate

threads to channel data to and from a subprocess:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Suntra_Vineeta at 2007-7-8 22:06:49 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks Suntra, your help fixed my problem right away.Message was edited by: tootles564
tootles564a at 2007-7-8 22:06:49 > top of Java-index,Java Essentials,New To Java...