Re: Executing command with Runtime.getRuntime.exec() fails
- From: Ingo Menger <quetzalcotl@xxxxxxxxxxxxxx>
- Date: Thu, 29 Nov 2007 04:43:30 -0800 (PST)
On 29 Nov., 13:23, Lionel <lione...@xxxxxxxxx> wrote:
I did in fact try using exec(String[]) but perhaps I tokenized it
incorrectly. This is what I tried:
String mysqlServiceCommand[] = {"cmd", "/c",
"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqld-nt.exe\"",
"--install", "MySQL1",
"--defaults-file=\"C:\\Program Files\\MySQL\\MySQL Server " +
"5.0\\my-large.ini\""};
What is the "cmd /c" for, except to make the program less portable?
I think one can trust that Runtime.exec will choose the right command
interpreter.
Actually, this might be the whole problem, since Runtime.exec will
pass your command string to the system default command interpreter
(which does tokenization). So it ends up like
cmd /c "cmd /c \"your program\""
when you want
cmd /c "your program" (on Windows)
and
sh -c "your prog" (under Linux)
This give the same error as before!
Do I need to tokenise at spaces?
No.
Consider how you type this command at the command prompt:
"C:\program files\foo.exe" baz
IMPORTANT: Try it out so that you're sure it works!
Then make a java string that contains *exactly* what you typed. This
means you have to quote backslashes and quotation marks:
String command = "\"C:\\program files\\foo.exe\" baz";
Now pass command to Runtime.exec().
.
- Follow-Ups:
- Re: Executing command with Runtime.getRuntime.exec() fails
- From: Nigel Wade
- Re: Executing command with Runtime.getRuntime.exec() fails
- From: Lionel van den Berg
- Re: Executing command with Runtime.getRuntime.exec() fails
- From: Patricia Shanahan
- Re: Executing command with Runtime.getRuntime.exec() fails
- References:
- Executing command with Runtime.getRuntime.exec() fails
- From: Lionel
- Re: Executing command with Runtime.getRuntime.exec() fails
- From: Gordon Beaton
- Re: Executing command with Runtime.getRuntime.exec() fails
- From: Lionel
- Executing command with Runtime.getRuntime.exec() fails
- Prev by Date: Re: Singleton and performance
- Next by Date: Re: Executing command with Runtime.getRuntime.exec() fails
- Previous by thread: Re: Executing command with Runtime.getRuntime.exec() fails
- Next by thread: Re: Executing command with Runtime.getRuntime.exec() fails
- Index(es):
Relevant Pages
|