我想使用字符串作为输入来调用 bash。就像是:
sh -l -c "./foo"
我想从 Java 中做到这一点。不幸的是,当我尝试使用 调用命令时getRuntime().exec
,出现以下错误:
foo": -c: line 0: unexpected EOF while looking for matching `"'
foo": -c: line 1: syntax error: unexpected end of file
这似乎与我的字符串没有被 EOF 终止有关。
有没有办法将特定于平台的 EOF 插入到 Java 字符串中?还是我应该寻找另一种方法,例如在调用 "sh" 之前写入临时脚本?