Exec() 未正确解释多个命令

发布于 2024-11-25 14:03:01 字数 300 浏览 1 评论 0原文

我试图通过 exec() 运行两个命令,但似乎这些命令没有正确解析。

我有以下行代码:

cmd = "scp -rp /mnt/backups/updateimage/images root@"+Arr.get(i)+":/usr/site/html ; ssh Arr.get(i)+" /usr/site/html/images/untar1.sh";

p = Runtime.getRuntime().exec(cmd);

知道如何格式化我的 cmd 字符串以便 exec 正确解释它吗? 谢谢

I am trying to run two commands through exec() but it seems as if the commands are not correctly parsed.

I have the following code of line:

cmd = "scp -rp /mnt/backups/updateimage/images root@"+Arr.get(i)+":/usr/site/html ; ssh Arr.get(i)+" /usr/site/html/images/untar1.sh";

p = Runtime.getRuntime().exec(cmd);

Any idea how can I format my cmd string so that exec interprets it correctly ?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉黛浅 2024-12-02 14:03:01

执行多个分号分隔的命令是 shell 提供的功能,但您正在执行 scp 命令。

如果您想使用 shell,则应指定 it 作为要执行的命令,并以实际命令作为其参数。

Execution of multiple, semi-colon delimited commands is feature provided by shells, but you are executing the scp command.

If you want to use a shell, you should specify it as the command to be executed, with the actual commands as its arguments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文