当前位置:首页 » 编程软件 » 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-14 00:38:54 浏览:192
单片机c语言视频下载 发布:2025-09-14 00:32:10 浏览:343
怎样改变存储位置 发布:2025-09-14 00:28:25 浏览:901
phpedit 发布:2025-09-14 00:26:50 浏览:228
sqlnotlike多个 发布:2025-09-14 00:20:15 浏览:867
ftp映射到本地 发布:2025-09-14 00:12:52 浏览:284
c语言叹号 发布:2025-09-14 00:00:23 浏览:124
rpg怎么电脑改安卓 发布:2025-09-13 23:51:35 浏览:835
c语言i6 发布:2025-09-13 23:51:23 浏览:739
32种算法 发布:2025-09-13 23:50:04 浏览:879