Re: Executing command with Runtime.getRuntime.exec() fails
- From: Lionel <lionelv_@xxxxxxxxx>
- Date: Thu, 29 Nov 2007 22:23:59 +1000
Gordon Beaton wrote:
On Thu, 29 Nov 2007 21:56:14 +1000, Lionel wrote:If I change mysqlServiceCommand to
"cmd /c \"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqld-nt.exe
--install MySQL1";
It works as expected.
Does anyone have any idea what's going on?
The string you pass to exec(String) gets tokenized before it's passed
to exec(String[]). The tokenizer breaks your command into whitespace
delimited tokens without regard to escaping, quoting or other special
characters.
In your particular example, you pass your arguments to a command shell
which does further processing to the command line (and probably
respects escapes, quotes etc) before the command itself gets executed
by the shell you specified.
Exactly how the two interact is not always clear, as you've
discovered. Try running a program that simply prints its arguments to
get a better understanding of the situation. Try it both with and
without "cmd /c".
If you want a greater degree of control over this, you can avoid the
initial tokenization done by exec(String) by instead calling
exec(String[]) directly. Break the command into tokens yourself
(exactly one per array element) without using extra quotation marks.
More detailed response of what Patrick also said, so I'll answer both here.
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\""};
This give the same error as before!
Do I need to tokenise at spaces?
thanks
Lionel.
.
- Follow-Ups:
- Re: Executing command with Runtime.getRuntime.exec() fails
- From: Gordon Beaton
- Re: Executing command with Runtime.getRuntime.exec() fails
- From: Ingo Menger
- 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
- Executing command with Runtime.getRuntime.exec() fails
- Prev by Date: Re: JNI UnsatisfiedLinkError
- Next by Date: Re: Singleton and performance
- 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
|