在Java Runtime中使用引号和双引号.getRuntime().exec(...) [英] Using quotes and double quotes in Java Runtime.getRuntime().exec(...)
问题描述
我正在尝试从Mac OSX中的Java启动Lisp映像.使用控制台中的图像,输入以下内容:
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")'
一切正常.
在Java中,我遇到了使用Runtime.getRuntime().exec("lisp_image --eval '(package::method \"some_argument\")'").
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\")'").
我也尝试使用:
Runtime.getRuntime().exec(new String[] {"lisp_image", "--eval ", "\'(package::method ",
"--eval ", "\"", "some_argument", "\")", "\'"});
以及使用反斜杠转义的各种内容.什么都行不通....使用字符串数组似乎仅适用于Unix(或Windows)命令.
and various things with escaping using the backslash. Nothing works.... Using String Array seems to work only for Unix (or Windows) commands.
有什么想法吗?
预先感谢, 斯文
推荐答案
据我了解,您想使用两个参数--eval和'(package :: method \"some_argument \"))调用list_image,其中单引号只是为了防止外壳将其分解为多个参数.
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.
那你应该使用
Runtime.getRuntime().exec(new String[] {"lisp_image", "--eval", "(package::method \"some_argument\")"});
这篇关于在Java Runtime中使用引号和双引号.getRuntime().exec(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!