Am 21.04.2013 00:56, schrieb Martin Gregorie:
Start reading from the top of the page:
http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html
The first bullet points explains, that on some operating systems (e.g.
Windows), a valid command exist of exactly two Strings.
It says *some* operating systems. No mention of Windows. It also says
"there are operating systems where programs are expected to tokenize
command line strings themselves" which is not Windows IME - the C, C++
and Java CLI programming interface is the same for these in UNIX, Linux,
OS-9 and Windows. There are probably some programming languages/
environments in which you'd be required to split out the CLI arguments
yourself (IIRC TAL on a Guardian NonStop system is one), but if you're
programing in that sort of environment then you'd be familiar with that
sort of CLI parsing and expect to do it.
The constructor of ProcessBuilder on the other hand states that it does
not check whether the provided list of strings is a valid command.
Of course. Its perfectly reasonable to expect the OS to determine whether
the first argument identifies a an executable file - every oyhet language
system (e.g. all the C standard library exec() functions work that way),
just as all command line arguments are passed to the called executable
for validation.
In short, if you've tried something like this:
ProcessBuilder pb = new ProcessBuilder("cmnd.exe", "arg1", "arg2",
"arg3");
pb.start();
and it doesn't work, try this:
ProcessBuilder pb = new ProcessBuilder("cmnd.exe", "arg1 arg2 arg3");
pb.start();
And for simplicity first try these with a program that is the equivalent
of:
public class Tester
{
public static main(String args)
{
for (int i = 0; i < args.length; i++)
System.out.println(args
);
}
}
but written is written in the same language as the program(s) you want to
run with ProcessBuilder. What results did you see?