{"record":{"id":"fbd1c8bd92fd446e","repo":"apache/cassandra","slug":"exception-while-executing-the-command","errorCode":null,"errorMessage":"Exception while executing the command: ","messagePattern":"Exception while executing the command: ","errorType":"console","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/FBUtilities.java","lineNumber":1221,"sourceCode":"    public static void exec(ProcessBuilder pb) throws IOException\n    {\n        Process p = pb.start();\n        try\n        {\n            int errCode = p.waitFor();\n            if (errCode != 0)\n            {\n                try (BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));\n                     BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream())))\n                {\n                    String lineSep = LINE_SEPARATOR.getString();\n                    StringBuilder sb = new StringBuilder();\n                    String str;\n                    while ((str = in.readLine()) != null)\n                        sb.append(str).append(lineSep);\n                    while ((str = err.readLine()) != null)\n                        sb.append(str).append(lineSep);\n                    throw new IOException(\"Exception while executing the command: \" + StringUtils.join(pb.command(), \" \") +\n                                          \", command error Code: \" + errCode +\n                                          \", command output: \" + sb);\n                }\n            }\n        }\n        catch (InterruptedException e)\n        {\n            throw new UncheckedInterruptedException(e);\n        }\n    }\n\n    /**\n     * Starts and waits for the given <code>cmd</code> to finish. If the process does not finish within <code>timeout</code>,\n     * it will be destroyed.\n     *\n     * @param env        additional environment variables to set\n     * @param timeout    timeout for the process to finish, or zero/null to wait forever\n     * @param outBufSize the maximum size of the collected std output; the overflow will be discarded","sourceCodeStart":1203,"sourceCodeEnd":1239,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/FBUtilities.java#L1203-L1239","documentation":"FBUtilities.exec (the ProcessBuilder-based helper) runs an external command and throws this IOException when the process exits with a non-zero error code, embedding the command line, exit code, and combined stdout/stderr output. It indicates the external tool invocation failed.","triggerScenarios":"Calling FBUtilities.exec(cmd) or execTimeout(...) where the spawned process returns a non-zero exit code, e.g. executing a native tool script that fails, missing arguments to the command, or a tool that errors on the host.","commonSituations":"Calls to external tools during repair/backup tooling, empty or wrong arguments to the command, the tool not supporting the requested operation on this OS, or environment issues (PATH, permissions) making the command fail after starting.","solutions":["Read the 'command output' section of the message to see the underlying tool's stderr","Verify the command and its arguments are correct for the current platform","Run the command manually on the host to reproduce and diagnose","Handle the specific exit code in the caller or add the required tool/dependency on the host"],"exampleFix":"// before: FBUtilities.exec(\"fio\", \"--name=test\", \"--bad-option\")\n// after:  FBUtilities.exec(\"fio\", \"--name=test\", \"--rw=read\", \"--size=1G\") // valid args","handlingStrategy":"try-catch","validationCode":"if (!new File(command[0]).canExecute() && FBUtilities.exec(\"which\", command[0]).isEmpty()) throw new IllegalStateException(\"tool not found: \" + command[0]);","typeGuard":null,"tryCatchPattern":"try { FBUtilities.exec(cmd); } catch (IOException e) { logger.error(\"External command failed: {}\", e.getMessage()); throw new RuntimeException(e); }","preventionTips":["Test external tool invocations manually with identical arguments","Capture and log the tool's stderr on failure","Verify tool availability and permissions on every node before use"],"tags":["process-execution","command","io"],"backgroundTag":"command-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}