標籤:class ict html time trace bin .exe error movies
1.指令碼test.sh,置於/Users/hdwang目錄下
#!/bin/shcd /Users/hdwangecho ls:`ls`for((i=1;i<=10;i++));doecho $(expr $i \* 3 + 1);sleep 1sdoneecho jps:`jps -l`
2.java執行test.sh
public class ExecShell { public static void main(String[] args) { try { Process pro = Runtime.getRuntime().exec("/Users/hdwang/test.sh"); InputStream in = pro.getInputStream(); BufferedReader read = new BufferedReader(new InputStreamReader(in)); String line = null; while((line = read.readLine())!=null){ System.out.println(line); } pro.waitFor(); } catch (Exception e) { e.printStackTrace(); } }}
3.執行結果
ls:App Applications Desktop Documents Downloads Library Movies Music Pictures Projects Public a.html c curl.txt java_error_in_idea.hprof mavenRepo nginx配置 res sessiontmp test.sh 記錄.txt 機器配置環境等 機器配置環境等.zip
4
7
10
13
16
19
22
25
28
31
jps:11617 sun.tools.jps.Jps 11592 org.jetbrains.jps.cmdline.Launcher 10633 org.jetbrains.jps.cmdline.Launcher 11593 com.hdwang.ExecShell 10539 com.hzxc.chess.server.Booter 555
java執行shell指令碼並輸出執行情況