当前位置:首页 » 编程软件 » 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

热点内容
it固定资产管理系统源码 发布:2025-09-16 00:35:42 浏览:354
Linux是搭建www服务器 发布:2025-09-16 00:35:34 浏览:339
php显示文字 发布:2025-09-16 00:20:25 浏览:280
轻量应用服务器可以搭建网站吗 发布:2025-09-16 00:13:19 浏览:993
压缩机外装 发布:2025-09-15 23:59:46 浏览:450
服务器的狗是什么 发布:2025-09-15 23:20:04 浏览:691
scaletypeandroid 发布:2025-09-15 23:08:27 浏览:636
c语言指针指向数组 发布:2025-09-15 23:04:07 浏览:868
刷妖气封印脚本 发布:2025-09-15 22:59:10 浏览:603
在线抓源码 发布:2025-09-15 22:51:57 浏览:259