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

I am trying to run Lisp Image from Java on Mac OSX. Using the image from my console, enter the following:

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

everything is working fine.

In Java, I have a problem with passing quotes and double quotes using Runtime.getRuntime().exec("lisp_image --eval '(package::method \"some_argument\")'").

I also tried using:

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

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

Any ideas?

Thanks in advance, Sven

+4
source share
1 answer

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

Then you should use

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

Source: https://habr.com/ru/post/1385078/


All Articles