如何在java程序中调用linux命令或者shell脚本
2个回答
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@Test
public void test6() {
BufferedReader br = null;
Runtime rt = Runtime.getRuntime();
String cmdstr = "cmd.exe /c dir";
try {
Process process = rt.exec(cmdstr);
//输入执行结果
br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while((line = br.readLine())!=null){
System.out.println(line);
}
if (process != null) {
process.destroy();
process = null;
}
} catch (IOException e) {
e.printStackTrace();
}finally{
if (br != null) {
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@Test
public void test6() {
BufferedReader br = null;
Runtime rt = Runtime.getRuntime();
String cmdstr = "cmd.exe /c dir";
try {
Process process = rt.exec(cmdstr);
//输入执行结果
br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while((line = br.readLine())!=null){
System.out.println(line);
}
if (process != null) {
process.destroy();
process = null;
}
} catch (IOException e) {
e.printStackTrace();
}finally{
if (br != null) {
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
2016-04-14 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
* public Process exec(String command);
* public Process exec(String [] cmdArray);
* public Process exec(String command, String [] envp);
* public Process exec(String [] cmdArray, String [] envp);
* public Process exec(String [] cmdArray);
* public Process exec(String command, String [] envp);
* public Process exec(String [] cmdArray, String [] envp);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询