I have faced a certain problem while writing the following code to
run a shell command through a Java Program....
The code is...
{ public static void termFrequencyVector() throws IOException
{
//String str1 = "man ls>test.txt";
//Process p = Runtime.getRuntime().exec(str1);
Runtime rt = Runtime.getRuntime();
String[] envp = { "PATH=/fs11/bt2003/ankans" };
Process p = rt.exec("ls", envp);
//String str1 = "ls>test.txt";
//Process p = Runtime.getRuntime().exec(str1);
}
public static void main(String [] args) throws Exception
{
termFrequencyVector();
}
}
I get the following error after the code compiles correctly...
Exception in thread "main" java.io.IOException: No such file or
directory
at java.lang.ConcreteProcess.startProcess(java.lang.String[],
java.lang.String[], java.io.File) (/usr/lib/libgcj.so.5.0.0)
at java.lang.ConcreteProcess.ConcreteProcess(java.lang.String[],
java.lang.String[], java.io.File) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Runtime.execInternal(java.lang.String[],
java.lang.String[], java.io.File) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Runtime.exec(java.lang.String[], java.lang.String[],
java.io.File) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Runtime.exec(java.lang.String, java.lang.String[],
java.io.File) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Runtime.exec(java.lang.String, java.lang.String[])
(/usr/lib/libgcj.so.5.0.0)
at TFIDF.termFrequencyVector() (Unknown Source)
at TFIDF.main(java.lang.String[]) (Unknown Source)
Please tell me whether it is possible to run commands like ls in this
way or am I writing the path name environment or command name wrong? I
dont think there is any mistake in the syntax of the code.
Rohit
Sebastian Scheid - 16 Jun 2005 15:22 GMT
> I have faced a certain problem while writing the following code to
> run a shell command through a Java Program....
You should read this article
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html . It
explains how to run shell commands under Windows (Listing 4.5
GoodWindowsExec.java). I think the explained problem applies to Linux, too.
Regards
Sebastian