Linux:j*a通过Runtime.getRuntime().exec()执行shell,Process.waitFor()返回Required key not *ailable(126)问题

问题使用方法Runtime.getRuntime().exec()调用并执行脚本Process.waitFor()方法返回值是否为0来确定是否成功执行(成功为0)返回错误码126查看Process.waitFor()方法的返回值:Required key not *ailable 操作系统错误代码126:所需的Key不可用排查

因为看到错误码对应的原因是:required key not *ailable,所需的key不可用。查找了很多相关解决办法,发现都不太相关。

于是只能捕捉进程的输出来看是否能找到蛛丝马迹 增加代码如下:

代码语言:j*ascript代码运行次数:0运行复制
Process proc = Runtime.getRuntime().exec(strMakePathPath);  StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "Error");  StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "Output");  errorGobbler.start();  outputGobbler.start();  proc.waitFor(); 
代码语言:j*ascript代码运行次数:0运行复制
import j*a.io.BufferedReader;import j*a.io.IOException;import j*a.io.InputStream;import j*a.io.InputStreamReader;public class StreamGobbler extends Thread {    InputStream is;    String type;    public StreamGobbler(InputStream is, String type) {        this.is = is;        this.type = type;    }    public void run() {        try {            InputStreamReader isr = new InputStreamReader(is);            BufferedReader br = new BufferedReader(isr);            String line = null;            while ((line = br.readLine()) != null) {                if (type.equals("Error")) {                    System.out.println("Error   :" + line);                } else {                    System.out.println("Debug:" + line);                }            }        } catch (IOException ioe) {            ioe.printStackTrace();        }    }}

校验输出如下error(当时忘记截图了,看红色字)

Linux:java通过Runtime.getRuntime().exec()执行shell,Process.waitFor()返回Required key not available(126)问题

于是去看了一下两个脚本的权限,结果果然有区别,第二个脚本没有可执行权限 所以问题是否在这里呢?

灵光 灵光

蚂蚁集团推出的全模态AI助手

灵光 1635 查看详情 灵光 解决

直接权限安排

代码语言:j*ascript代码运行次数:0运行复制
chmod 777  文件

再次执行代码,发现问题解决了

结论

j*a通过Runtime.getRuntime().exec()执行shell,Process.waitFor()返回Required key not *ailable(126)问题的解决办法:可以看一下文件权限是否有问题

以上就是Linux:j*a通过Runtime.getRuntime().exec()执行shell,Process.waitFor()返回Required key not *ailable(126)问题的详细内容,更多请关注其它相关文章!

本文转自网络,如有侵权请联系客服删除。