{"record":{"id":"6a23fb0213ac23c0","repo":"nextcloud/server","slug":"cannot-open-stdin-for-read-operation","errorCode":null,"errorMessage":"Cannot open stdin for read operation.","messagePattern":"Cannot open stdin for read operation\\.","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"apps/dav/lib/Command/ImportCalendar.php","lineNumber":117,"sourceCode":"\t\t$options->setSupersede($supersede);\n\t\tif ($errors !== null) {\n\t\t\t$options->setErrors($errors);\n\t\t}\n\t\tif ($validation !== null) {\n\t\t\t$options->setValidate($validation);\n\t\t}\n\t\t$options->setFormat($format);\n\t\t$options->setCounts(true);\n\t\t// evaluate if a valid location was given and is usable otherwise default to stdin\n\t\tif ($location !== null) {\n\t\t\t$stream = fopen($location, 'r');\n\t\t\tif ($stream === false) {\n\t\t\t\tthrow new InvalidArgumentException(\"Location <$location> is not valid. Cannot open location for read operation.\");\n\t\t\t}\n\t\t} else {\n\t\t\t$stdin = fopen('php://stdin', 'r');\n\t\t\tif ($stdin === false) {\n\t\t\t\tthrow new InvalidArgumentException('Cannot open stdin for read operation.');\n\t\t\t}\n\t\t\t$tempPath = $this->tempManager->getTemporaryFile();\n\t\t\t$stream = fopen($tempPath, 'w+');\n\t\t\twhile (!feof($stdin)) {\n\t\t\t\tfwrite($stream, fread($stdin, 8192));\n\t\t\t}\n\t\t\tfclose($stdin);\n\t\t\tfseek($stream, 0);\n\t\t}\n\t\t$timeStarted = microtime(true);\n\t\t$totalCreated = 0;\n\t\t$totalUpdated = 0;\n\t\t$totalSkipped = 0;\n\t\t$totalErrors = 0;\n\t\ttry {\n\t\t\tforeach ($this->importService->import($stream, $calendar, $options) as $event) {\n\t\t\t\tif ($event instanceof ImportCountEvent) {\n\t\t\t\t\t$output->writeln('Total objects to import: ' . $event->total());","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Command/ImportCalendar.php#L99-L135","documentation":"InvalidArgumentException thrown by occ dav:import-calendar (apps/dav/lib/Command/ImportCalendar.php:117) when fopen('php://stdin','r') returns false - the command fell back to stdin because no input file argument was given, but STDIN could not be opened. This only happens in abnormal runtime contexts where the php://stdin stream is unavailable.","triggerScenarios":"Running occ dav:import-calendar alice personal with no location argument from an environment where stdin is closed/inaccessible (cron/cronjob context with closed fds, some container supervisors, proc_open without a stdin pipe).","commonSituations":"Automations invoking occ without an attached TTY and with stdin closed; Docker/Kubernetes entrypoints that close fd 0; wrappers that detach standard streams.","solutions":["Pass an explicit input file as the location argument instead of relying on stdin","Ensure fd 0 is open (redirect from /dev/null: occ ... < /dev/null will still fail here - prefer a file path)","Run via a proper shell or supervisor that provides standard streams"],"exampleFix":"# before (stdin closed in cron/container)\nocc dav:import-calendar alice personal\n# after (explicit input file)\nocc dav:import-calendar alice personal /var/imports/calendar.ics","handlingStrategy":"fallback","validationCode":"// in automations, always provide the file argument so stdin is not needed\n$cmd = \"occ dav:import-calendar $uid $uri /abs/path/input.ics\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never rely on stdin from cron/container contexts","Mount or copy import files to paths visible to the occ user","Ensure fd 0 is provided when wrapping occ with proc_open"],"tags":["occ","cli","import","calendar","stdin","stream-unavailable"],"backgroundTag":"standard-input-unavailable","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}