nextcloud/server · error · InvalidArgumentException
Cannot open stdin for read operation.
Error message
Cannot open stdin for read operation.
What it means
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.
Source
Thrown at apps/dav/lib/Command/ImportCalendar.php:117
$options->setSupersede($supersede);
if ($errors !== null) {
$options->setErrors($errors);
}
if ($validation !== null) {
$options->setValidate($validation);
}
$options->setFormat($format);
$options->setCounts(true);
// evaluate if a valid location was given and is usable otherwise default to stdin
if ($location !== null) {
$stream = fopen($location, 'r');
if ($stream === false) {
throw new InvalidArgumentException("Location <$location> is not valid. Cannot open location for read operation.");
}
} else {
$stdin = fopen('php://stdin', 'r');
if ($stdin === false) {
throw new InvalidArgumentException('Cannot open stdin for read operation.');
}
$tempPath = $this->tempManager->getTemporaryFile();
$stream = fopen($tempPath, 'w+');
while (!feof($stdin)) {
fwrite($stream, fread($stdin, 8192));
}
fclose($stdin);
fseek($stream, 0);
}
$timeStarted = microtime(true);
$totalCreated = 0;
$totalUpdated = 0;
$totalSkipped = 0;
$totalErrors = 0;
try {
foreach ($this->importService->import($stream, $calendar, $options) as $event) {
if ($event instanceof ImportCountEvent) {
$output->writeln('Total objects to import: ' . $event->total());View on GitHub (pinned to ecdeb153ff)
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
Example fix
# before (stdin closed in cron/container) occ dav:import-calendar alice personal # after (explicit input file) occ dav:import-calendar alice personal /var/imports/calendar.ics
Defensive patterns
Strategy: fallback
Validate before calling
// in automations, always provide the file argument so stdin is not needed $cmd = "occ dav:import-calendar $uid $uri /abs/path/input.ics";
Prevention
- 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
When it happens
Trigger: 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).
Common situations: Automations invoking occ without an attached TTY and with stdin closed; Docker/Kubernetes entrypoints that close fd 0; wrappers that detach standard streams.
Related errors
- User <$userId> not found.
- Calendar <$calendarId> not found
- Calendar <$calendarId> doesn't support this function
- Calendar <$calendarId> is not writeable
- Calendar <$calendarId> is deleted
AI-assisted analysis of nextcloud/server@ecdeb153ff (2026-08-17).
Data as JSON: /api/errors/6a23fb0213ac23c0.
Report an issue: GitHub.