Re: Executing command with Runtime.getRuntime.exec() fails
- From: Gordon Beaton <n.o.t@xxxxxxxxx>
- Date: 29 Nov 2007 12:08:35 GMT
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.
And just for fun, IIRC the actual behaviour is slightly different on
windows and unix platforms, and depends highly on the actual choice of
command shell specified.
/gordon
--
.
- Follow-Ups:
- References:
- Prev by Date: Re: Executing command with Runtime.getRuntime.exec() fails
- Next by Date: Re: JNI UnsatisfiedLinkError
- 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
|