當前位置:首頁 » 編程軟體 » java如何去寫shell腳本

java如何去寫shell腳本

發布時間: 2022-07-08 21:20:33

A. 如何在java中執行shell腳本

import java.io.IOException;

public class test {
public static void main(String[] args) throws IOException,InterruptedException {
//Runtime.getRuntime().exec("/Users/lijialiang/codetest/stop.sh jmeter");
//Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","/codetest/stop.sh jmeter"});
//Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","ps -ef | grep jmeter | grep -v 'grep' |awk '{print $2}'>>result.txt"});
Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","ps -ef | grep <span style="font-family: Arial, Helvetica, sans-serif;">jmeter</span><span style="font-family: Arial, Helvetica, sans-serif;"> | awk '{print $2}' | xargs kill -9"});</span>
//Thread.sleep(100000);
}
}

B. java shell腳本怎麼寫

  • java-cp"./classes:./classlib"-Dparam1=zzzzztest.myclass$0

  • -cp指定classpath

  • -D指定一個參數,程序內用System.getProperty("param1")訪問

  • $0把外部調用的參數傳遞給javaclass

C. 如何在java中執行shell腳本

在java中執行shell腳本 用法:Runtime.getRuntime().exec("命令");
String shpath="/test/test.sh"; //程序路徑
Process process =null;
String command1 = 「chmod 777 」 + shpath;
try {
Runtime.getRuntime().exec(command1 ).waitFor();
} catch (IOException e1) {
e1.printStackTrace();
}catch (InterruptedException e) {
e.printStackTrace();
}

String var="201102"; /參數
String command2 = 「/bin/sh 」 + shpath + 」 」 + var;
Runtime.getRuntime().exec(command2).waitFor();

D. 使用java怎麼寫一個shell腳本

  1. java-cp"./classes:./classlib"-Dparam1=zzzzztest.myclass$0

  2. -cp指定classpath

  3. -D指定一個參數,程序內用System.getProperty("param1")訪問

  4. $0把外部調用的參數傳遞給javaclass

熱點內容
安卓開發選哪個版本的SDK 發布:2025-07-02 22:19:07 瀏覽:484
未上傳圖片 發布:2025-07-02 22:14:01 瀏覽:598
安卓qq直播怎麼分享聲音 發布:2025-07-02 22:13:21 瀏覽:249
安卓系統怎麼刷機清除內存 發布:2025-07-02 22:08:19 瀏覽:696
安卓手機6位數密碼有多少組 發布:2025-07-02 21:50:31 瀏覽:797
存儲卡視頻多了 發布:2025-07-02 21:49:40 瀏覽:850
ajax無刷新上傳圖片 發布:2025-07-02 21:32:56 瀏覽:117
編譯器不認pow函數 發布:2025-07-02 21:27:04 瀏覽:339
w10隱藏文件夾 發布:2025-07-02 21:27:03 瀏覽:534
電腦d盤拒絕訪問 發布:2025-07-02 21:27:02 瀏覽:779