gpt4 book ai didi

java - 从 java 代码运行脚本 shell

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:06 25 4
gpt4 key购买 nike

<分区>

我在下面有这个脚本(称为 compute.sh 并用于启动 ROOT 应用程序(CERN)(root.exe)并用它执行一些 c++ 宏)

#!/bin/bash
ROOTSH=/path/to/files root -b -l macro.cpp
$ROOTSH &
ROOT_PID=$!
echo $ROOT_PID > .lock

为了从我在同一台 Linux 服务器上部署的 java 应用程序启动这个 .sh:

try{  
Process p = Runtime.getRuntime().exec("/path/to/files/compute.sh");
p.waitFor();
}catch( IOException ex ){
log.warn("Cannot find bat or sh to start ROOT");
}catch( InterruptedException ex ){
log.warn("The ROOT execution is interrupted");
}

但是当我尝试从 UI 启动这个 .sh 时,我什么也没有,没有结果也没有错误。当我从 Java 代码外部运行 .sh 时,它运行良好。

有没有人知道如何处理这个问题?或者是否有另一种方法来确保 shell 脚本将从 java 代码运行?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com