Problem with Runtime.getRuntime().exec()

R

Rohit Gupta

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top