Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using quotes and double quotes in Java Runtime.getRuntime().exec(...)

I am trying to start a Lisp Image from Java in Mac OSX. Using the Image from my console I type the following:

lisp_image --eval '(package::method "some_argument")'

everything runs fine.

In Java I have the problem to pass the quotes and double quotes using the Runtime.getRuntime().exec("lisp_image --eval '(package::method \"some_argument\")'").

I also tried to use :

Runtime.getRuntime().exec(new String[] {"lisp_image", "--eval ", "\'(package::method ", 
           "--eval ", "\"", "some_argument", "\")", "\'"});

and various things with escaping using the backslash. Nothing works.... Using String Array seems to work only for Unix (or Windows) commands.

Any ideas?

Thanks in advance, Sven

like image 806
svendeswan Avatar asked Dec 07 '11 09:12

svendeswan


1 Answers

As I understand it you want to invoke the list_image with two arguments, --eval and '(package::method \"some_argument\")' where the single quotes is just there to prevent the shell from breaking it up into multiple arguments.

Then you should use

Runtime.getRuntime().exec(new String[] {"lisp_image", "--eval", "(package::method \"some_argument\")"});
like image 55
Roger Lindsjö Avatar answered Sep 21 '22 10:09

Roger Lindsjö