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

1

5

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

Richmond answered 7/12, 2011 at 9:46 Comment(1)
Did you look at: javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1 ?Disconcert
A
12

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\")"});
Alurd answered 7/12, 2011 at 9:55 Comment(2)
GREAT ! It's the single quotes :-) Thank you so much !Richmond
@svendeswan, you may want to accept the answer if its worked for you :-)Moonshiner

© 2022 - 2024 — McMap. All rights reserved.