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



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().
.



Relevant Pages

  • Re: How To Execute Batch File Line By Line
    ... COMMAND /C string Carries out the command specified by string, ... CMD /C Carries out the command specified by string and then terminates. ... .cmd files will NOT work on non Windows NT versions i.e. Windows 9x, ... Both .cmd and .bat files work on Windows NT versions. ...
    (microsoft.public.windowsxp.general)
  • Re: Command.Com - Sinn und Unsinn?
    ... Kompatibilität für 16-Bit-Porgs dient, dann gilt das auch ... Anforderung die ich an CMD / Command stelle! ... Ich habe seit DOS 4 "Fachwissen" um DOS - und wenn ich ...
    (microsoft.public.de.german.windowsxp.sonstiges)
  • Re: MSinfo32.exe help
    ... when i do the cmd for rd packagestore /s /q(system cant find file ... use it even though i have to use cmd to open it.this bothers me alot i defrag ... my packagestore folder didn't have any .cab files in it ... > command in case there's a problem with word wrap. ...
    (microsoft.public.windowsxp.general)
  • Re: A clean way to program an interface
    ... Yes - You are correct UnidenConnection is nothing more than a pyserial ... with his naming of certain methods with the same name as the command ... def makeStatusCheckCommandFunction: ... the command strings are just passed along as the argument cmd, ...
    (comp.lang.python)
  • Re: Results from Rameshs commands
    ... > Type this command in Start, ... use this DIR command in the Command Prompt: ... > I used an old clean tool to uninstall One Care (provided by One Care ... I can at the cmd prompt. ...
    (microsoft.public.windowsxp.customize)