Java - 执行.SH文件 [英] Java - Execute a .SH file

查看:164
本文介绍了Java - 执行.SH文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何执行.SH文件(这是localhost,没有远程连接或任何东西)?我在搜索时看到了很多 Runtime.exec 和其他东西,但这些似乎没有用。

How would I go about executing a .SH file (this is localhost, no remote connection or anything)? I've seen lots of Runtime.exec and other things when I searched but those didn't seem to work.

这是Java 6.此外,如果重要的是,所有SH正在做的是移动两个文件夹。

This is Java 6. Also if it matters, all the SH is doing is moving two folders around.

谢谢!

推荐答案

你可以使用 ProcessBuilder

 ProcessBuilder pb = new ProcessBuilder("myshell.sh", "myArg1", "myArg2");
 Process p = pb.start();
 BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
 String line = null;
 while ((line = reader.readLine()) != null)
 {
    System.out.println(line);
 }

这篇关于Java - 执行.SH文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆