當前位置:首頁 » 編程軟體 » 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

熱點內容
存儲資料庫工作原理 發布:2025-09-13 22:54:33 瀏覽:639
html5批量文件上傳 發布:2025-09-13 22:51:24 瀏覽:61
資料庫開發應用 發布:2025-09-13 22:36:56 瀏覽:352
php描述 發布:2025-09-13 22:09:25 瀏覽:207
sql2000死鎖 發布:2025-09-13 21:57:48 瀏覽:766
F7編譯 發布:2025-09-13 21:55:53 瀏覽:592
怎樣使用sql 發布:2025-09-13 21:55:51 瀏覽:188
墨跡天氣怎麼取消隱藏的伺服器 發布:2025-09-13 21:36:28 瀏覽:37
sql資料庫入門到精通 發布:2025-09-13 20:13:50 瀏覽:741
微信設密碼鎖在哪裡設華為手機 發布:2025-09-13 20:04:03 瀏覽:146