{"record":{"id":"8f5b327ac4970e35","repo":"apache/hadoop","slug":"error-executing-command-s-process-exited-with-ex","errorCode":null,"errorMessage":"Error executing command. %s Process exited with exit code %d.","messagePattern":"Error executing command\\. (.+?) Process exited with exit code (.+?)\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":963,"sourceCode":"            inputStream, process.getOutputStream());\n      } finally {\n        process.getOutputStream().close();\n      }\n\n      // Wait for both stdout and stderr futures to finish\n      error.get();\n      output.get();\n    } finally {\n      // Clean up the threads\n      if (executor != null) {\n        executor.shutdown();\n      }\n      // Wait to avoid leaking the child process\n      exitCode = process.waitFor();\n    }\n\n    if (exitCode != 0) {\n      throw new IOException(\n          String.format(\n              \"Error executing command. %s \" +\n                  \"Process exited with exit code %d.\",\n              command, exitCode));\n    }\n  }\n\n  /**\n   * Given a Tar File as input it will untar the file in a the untar directory\n   * passed as the second parameter\n   *\n   * This utility will untar \".tar\" files and \".tar.gz\",\"tgz\" files.\n   *\n   * @param inputStream The tar file as input.\n   * @param untarDir The untar directory where to untar the tar file.\n   * @param gzipped The input stream is gzipped\n   *                TODO Use magic number and PusbackInputStream to identify\n   * @throws IOException an exception occurred","sourceCodeStart":945,"sourceCodeEnd":981,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L945-L981","documentation":"The private runCommand helper used by unTar(InputStream, ...) on non-Windows pipes the input stream into an external process, and after draining stdout/stderr futures and process.waitFor(), a non-zero exit code yields IOException(\"Error executing command. <command> Process exited with exit code <n>.\"). The command array is the tar invocation ('bash','-c','tar -xf - ...'). So this error means the spawned tar (or bash) failed on your archive.","triggerScenarios":"unTar(stream, untarDir, gzipped) with a truncated/corrupt tar or tar.gz (tar exits 1/2); 'tar' binary missing from PATH (shell exit 127); gzipped=false on a .gz stream; target dir unwritable (tar cannot write).","commonSituations":"Partially downloaded tarballs; archives corrupted in transit; minimal container images without tar installed; wrong gzipped flag derived from filename heuristics.","solutions":["Verify the archive integrity first: gzip -t / tar -tf locally or via checksum against the source","Confirm the node has bash and tar on PATH (containers based on distroless/scratch often do not)","Pass the correct gzipped flag — the API relies on it rather than magic-number detection (see TODO in the source)","Catch the IOException, inspect the exit code in the message, and fall back to unTarUsingJava if the platform tar is the problem"],"exampleFix":"// before\nFileUtil.unTar(Files.newInputStream(tgz.toPath()), outDir, true);\n// IOException: Error executing command. ... exit code 2\n\n// after: validate gzip integrity before untarring\ntry (GzipCompressorInputStream g =\n         new GzipCompressorInputStream(Files.newInputStream(tgz.toPath()))) {\n  byte[] buf = new byte[8192];\n  while (g.read(buf) != -1) { /* drain to verify */ }\n}\nFileUtil.unTar(Files.newInputStream(tgz.toPath()), outDir, true);","handlingStrategy":"try-catch","validationCode":"// verify the tar binary exists and the stream is the expected format\nif (new File(\"/bin/tar\").canExecute() || Shell.checkIsBashSupported()) { /* ok */ }\nbyte[] magic = new byte[2];\ntry (PushbackInputStream pb = new PushbackInputStream(in, 2)) {\n  pb.read(magic);\n  pb.unread(magic);\n  boolean gz = (magic[0] & 0xff) == 0x1f && (magic[1] & 0xff) == 0x8b;\n  FileUtil.unTar(pb, untarDir, gz); // stop guessing the gzipped flag\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileUtil.unTar(in, untarDir, gzipped);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"exit code\")) {\n    // parse the exit code: 127 = tar missing, 1/2 = corrupt archive\n    // verify archive, install tar, or fall back to a Java-based untar\n  } else throw e;\n}","preventionTips":["Verify tar is installed in container images used for extraction","Detect gzip by magic bytes instead of filenames","Checksum-verify archives after transfer before untarring"],"tags":["untar","subprocess","exit-code","corrupt-archive","archive-extraction"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}