Exec() 未正确解释多个命令
我试图通过 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行多个分号分隔的命令是 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.