Re: Executing command with Runtime.getRuntime.exec() fails



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

--
.



Relevant Pages

  • Re: Executing command with Runtime.getRuntime.exec() fails
    ... The tokenizer breaks your command into whitespace ... delimited tokens without regard to escaping, ... you pass your arguments to a command shell ...
    (comp.lang.java.programmer)
  • Re: Windows XP Home file sharing access denied
    ... >>>use this network resource. ... Type the "exit" command to close the command shell window. ...
    (microsoft.public.windowsxp.general)
  • Re: extract variable after running exec xtclsh
    ... I was able to source the file successfully and use the command inside ... that I got in the command shell is a whole list of things. ... things out myself with the console, but I am stump with sourcing this ... But I don't know how to set up window to do this. ...
    (comp.lang.tcl)
  • Re: Windows XP Home file sharing access denied
    ... >>Hi Steve ... > the commands in the window that opens when you run the command shell. ... > Type the "exit" command to close the command shell window. ...
    (microsoft.public.windowsxp.general)
  • Re: Miniapps within XP
    ... [[The command shell is a separate software program that provides direct ... Windows XP command shell uses the command interpreter Cmd.exe, ... hh.exe is what opens *.chm ...
    (microsoft.public.windowsxp.newusers)