error = 2,java.lang.UNIXProcess.forkAndExec(本机方法)中没有此类文件或目录

时间:2017-12-13 09:23:13

标签: java

我编写了一个java程序,使用fping协议定期监视设备的状态。它将每5分钟执行fping命令。我有时只得到一个上述例外。我们正在使用这个目录(/ usr / local / bin /)。这是安装fping的地方。请建议。

public static List<String> executeProcess(String command,List<String> args,String dirPath) throws Exception {

        // delegate
        args.add(0,command);
        args.add(1,FpingSession.FPING_RETRY);
        args.add(2,FpingSession.FPING_RETRY_VALUE);
        ProcessBuilder processBuilder = new ProcessBuilder(args);
        if(dirPath!=null && !dirPath.isEmpty())
            processBuilder.directory(new File(dirPath));

        List<String> stringList;
        Process process = null;
        InputStream inputStream = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        try {
            process = processBuilder.start();

            inputStream = process.getInputStream();
            inputStreamReader = new InputStreamReader(
                    inputStream);
            bufferedReader = new BufferedReader(
                    inputStreamReader);
            stringList = new LinkedList<String>();
            while (true) {
                // next line
                final String string = bufferedReader.readLine();
                if (string == null) {
                    break;
                }
                // track
                stringList.add(string);
            }
        } finally{
            if (process != null)
                process.destroy();
            if (inputStream != null)
                inputStream.close();
            if (inputStreamReader != null)
                inputStreamReader.close();
            if (bufferedReader != null)
                bufferedReader.close();
        }
        // done

        return stringList;
}

0 个答案:

没有答案