91名师指路-头部
91名师指路

java调用shell脚本

由于某些原因,现在不支持支付宝支付,如需要购买源码请加博主微信进行购买,微信号:13248254750

一:代码

public static void main(String[] args) {
log.info("开始调用shell脚本");
try {
Runtime runtime = Runtime.getRuntime(); // 创建 Runtime 对象
Process process = runtime.exec("sh /data/postgresql-11/pgbak/xiaobo.sh"); // 执行 shell 命令或脚本
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); // 获取命令的输出流
String line;
while ((line = reader.readLine()) != null) {
log.info("syncData {}", line);
}

int exitCode = process.waitFor(); // 等待命令执行完毕并获取返回值
log.info("exit code: {}", exitCode);
} catch (Exception e) {
e.printStackTrace();
}

log.info("结束调用shell脚本");
}


参考资料:

https://blog.csdn.net/qq_35861084/article/details/143684318




2025-06-03 09:28:33     阅读(9)

名师出品,必属精品    https://www.91mszl.com

联系博主    
用户登录遮罩层
x

账号登录

91名师指路-底部