Runtime.exec error on Fedora Core
Hi,
I have some difficulty using Runtime.exec method on Fedora Core.
If classpath contains "space", it cannot execute a commnad.
It works well on Windows systems with quotation marks.
Here's my code.
Proccess p = r.exec("java -classpath .:\"pkg root"\" A");
Java command regards root as a class. It is actually a half of directory name. How can I solve this problem?
thank you for reading.
[447 byte] By [
eXtremea] at [2007-11-26 14:54:08]

That shouldn't work on Windows either.
If you call the exec() that takes a single argument, it splits up the string by spaces, IIRC. That means that '..:"pkg' and 'root"' will be two separate arguments, which probably isn't what you want. It should do the same thing on Windows.
Unless the JVM executable arguments-processing code on Windows has some mechanism to try recombining separate arguments, adding a space, I don't see how this would work on Windows either.
Anyway, use a version of exec() in which you pass it an array of String for arguments. Then you could put "pkg root" in a single argument.
I've tried an array of String arguments version of exec().
But, It doesn't work.
Would you give an example or a tip to run my external java program that contains "spcace" classpath?
Regards,
eXtreme.
PS> I cannot use external classpath variable because classpath is differencated based on each user's path.
This setting works for me on Linux:
[ebank2@giskard ivan]$ java b
here is a - have a nice day!
[ebank2@giskard ivan]$ cat "a b"/a.java
public class a {
public static void main (String a[] ) {
System.out.println("here is a - have a nice day!");
}
}
[ebank2@giskard ivan]$ cat b.java
import java.io.*;
public class b {
static String s[]={ "java" , "-classpath" , "a b" , "a" };
public static void main (String a[] ) throws Exception {
Process p = Runtime.getRuntime().exec(s);
InputStream is = p.getInputStream() ;
int c;
while((c=is.read()) != -1) System.out.print((char)c);
}
}