{"record":{"id":"29f1f8733209c871","repo":"iBotPeaches/Apktool","slug":"could-not-exec","errorCode":null,"errorMessage":"could not exec: ","messagePattern":"could not exec: ","errorType":"exception","errorClass":"BrutException","httpStatus":null,"severity":"error","filePath":"brut.j.util/src/main/java/brut/util/OS.java","lineNumber":150,"sourceCode":"                cpfile(file, destFile);\n            }\n        }\n    }\n\n    public static void exec(String[] cmd) throws BrutException {\n        try {\n            ProcessBuilder builder = new ProcessBuilder(cmd);\n            Process ps = builder.start();\n\n            new StreamForwarder(ps.getErrorStream(), \"ERROR\").start();\n            new StreamForwarder(ps.getInputStream(), \"OUTPUT\").start();\n\n            int exitValue = ps.waitFor();\n            if (exitValue != 0) {\n                throw new BrutException(\"Execution failed (exit code = \" + exitValue + \"): \" + Arrays.toString(cmd));\n            }\n        } catch (IOException ex) {\n            throw new BrutException(\"could not exec: \" + Arrays.toString(cmd), ex);\n        } catch (InterruptedException ex) {\n            throw new BrutException(\"could not exec : \" + Arrays.toString(cmd), ex);\n        }\n    }\n\n    public static String execAndReturn(String[] cmd) {\n        ExecutorService executor = Executors.newCachedThreadPool();\n        try {\n            ProcessBuilder builder = new ProcessBuilder(cmd);\n            builder.redirectErrorStream(true);\n\n            Process process = builder.start();\n            StreamCollector collector = new StreamCollector(process.getInputStream());\n            executor.execute(collector);\n            process.waitFor(15, TimeUnit.SECONDS);\n            executor.shutdownNow();\n\n            if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.j.util/src/main/java/brut/util/OS.java#L132-L168","documentation":"Thrown by OS.exec when ProcessBuilder.start() raises IOException — the process was never created. Typical causes: the executable does not exist (message often 'Cannot run program ... No such file or directory'), is not executable, or the OS refused the spawn (fork limit, permission denied). The failed command array is included in the message and the IOException is the cause.","triggerScenarios":"OS.exec(cmd) where cmd[0] names a binary not on PATH or at a wrong absolute path, the file lacks the execute bit, or it is a directory; also spawn failures such as EMFILE/ENOMEM under heavy load.","commonSituations":"Extracted native helper (aapt and friends) not marked +x or extracted to a path containing spaces that was not quoted in argv; PATH differs in CI/containers versus local shell; 32-bit binary on a 64-bit-only image; running on a JRE without the required exec permission in sandboxed environments.","solutions":["Verify the executable resolves and is runnable before exec: new File(cmd[0]).canExecute() or 'which <bin>'","chmod +x the extracted binary after pulling it out of the jar (Jar extraction does not preserve the exec bit)","Use an absolute path to the binary instead of relying on PATH, and confirm no unquoted spaces in each argv element","On 64-bit-only systems, install 32-bit compatibility libs or point to a 64-bit build of the tool"],"exampleFix":"// before\nOS.exec(new String[]{\"/tmp/BRUT123/aapt\", \"v\"}); // IOException: cannot run program\n\n// after\nFile bin = new File(\"/tmp/BRUT123/aapt\");\nif (!bin.canExecute() && !bin.setExecutable(true)) {\n    throw new BrutException(\"Cannot make executable: \" + bin);\n}\nOS.exec(new String[]{bin.getAbsolutePath(), \"v\"});","handlingStrategy":"validation","validationCode":"void ensureExecutable(String binPath) throws IOException {\n    File bin = new File(binPath);\n    if (!bin.isFile()) throw new FileNotFoundException(binPath);\n    if (!bin.canExecute() && !bin.setExecutable(true)) {\n        throw new IOException(\"cannot mark executable: \" + binPath);\n    }\n}\n// ensureExecutable(cmd[0]); OS.exec(cmd);","typeGuard":null,"tryCatchPattern":"try {\n    OS.exec(cmd);\n} catch (BrutException e) {\n    if (e.getCause() instanceof IOException\n            && e.getCause().getMessage().contains(\"No such file\")) {\n        // binary missing: fix PATH or extraction, not retryable\n        throw new EnvironmentException(\"tool not found: \" + cmd[0], e);\n    }\n    throw e;\n}","preventionTips":["Set the execute bit right after extracting binaries from jars","Prefer absolute binary paths over PATH lookup in CI and containers","Keep each argv element free of embedded spaces, or quote at the ProcessBuilder-array level (never string-join)"],"tags":["process","exec","permissions","environment","java"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}