{"record":{"id":"6af0dac1f54df518","repo":"apache/hadoop","slug":"stdin-must-be-the-sole-input-argument-when-pre","errorCode":null,"errorMessage":"stdin (-) must be the sole input argument when present","messagePattern":"stdin \\(-\\) must be the sole input argument when present","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java","lineNumber":407,"sourceCode":"      super.processOptions(args);\n    }\n\n    @Override\n    protected void processArguments(LinkedList<PathData> args)\n        throws IOException {\n\n      if (!dst.exists) {\n        dst.fs.create(dst.path, false).close();\n      }\n\n      InputStream is = null;\n      try (FSDataOutputStream fos = appendToNewBlock ?\n          dst.fs.append(dst.path, true) : dst.fs.append(dst.path)) {\n        if (readStdin) {\n          if (args.size() == 0) {\n            IOUtils.copyBytes(System.in, fos, DEFAULT_IO_LENGTH);\n          } else {\n            throw new IOException(\n                \"stdin (-) must be the sole input argument when present\");\n          }\n        }\n\n        // Read in each input file and write to the target.\n        for (PathData source : args) {\n          is = Files.newInputStream(source.toFile().toPath());\n          IOUtils.copyBytes(is, fos, DEFAULT_IO_LENGTH);\n          IOUtils.closeStream(is);\n          is = null;\n        }\n      } finally {\n        if (is != null) {\n          IOUtils.closeStream(is);\n        }\n      }\n    }\n  }","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java#L389-L425","documentation":"IOException('stdin (-) must be the sole input argument when present') thrown by AppendToFile.processArguments (CopyCommands.java:407). The command noticed readStdin==true (an argument was '-') but additional file arguments were also supplied. appendToFile reads either stdin or a list of files per invocation, never both, so the mix is rejected when the output stream is already open.","triggerScenarios":"'hadoop fs -appendToFile - extra.txt /dst'; a script conditionally builds an arg list that keeps '-' while also appending file names: ARGS='-'; for f in *.log; do ARGS=\"$ARGS $f\"; done.","commonSituations":"Pipelines that stream a header from stdin then append files; arg-list builders in bash that seed the list with '-' and forget to drop it when files are added.","solutions":["Use stdin alone: 'cat data | hadoop fs -appendToFile - /dst'","Or use files alone: 'hadoop fs -appendToFile a.log b.log /dst' — append the same destination again in a second call to get both inputs","Fix the arg-building script so '-' and file names are mutually exclusive branches"],"exampleFix":"# before\nARGS=\"-\"\nfor f in *.log; do ARGS=\"$ARGS $f\"; done\nhadoop fs -appendToFile $ARGS /dst     # stdin (-) must be the sole input argument\n\n# after\ncat header.txt | hadoop fs -appendToFile - /dst\nhadoop fs -appendToFile *.log /dst","handlingStrategy":"validation","validationCode":"boolean hasStdin = args.contains(\"-\");\nif (hasStdin && args.size() > 1) {\n  throw new IOException(\"stdin (-) must be the sole input argument when present\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  // process append inputs\n} catch (IOException e) {\n  if (e.getMessage().contains(\"sole input argument\")) {\n    // split into two invocations: one for '-', one for the files\n  }\n}","preventionTips":["Treat '-' as mutually exclusive with file arguments when building arg lists","When appending a header plus files, run two appendToFile calls against the same destination"],"tags":["hadoop","appendtofile","shell","stdin","argument-validation"],"backgroundTag":"invalid-command-arguments","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}