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

  1. Pass an explicit input file as the location argument instead of relying on stdin
  2. Ensure fd 0 is open (redirect from /dev/null: occ ... < /dev/null will still fail here - prefer a file path)
  3. 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

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


AI-assisted analysis of nextcloud/server@ecdeb153ff (2026-08-17). Data as JSON: /api/errors/6a23fb0213ac23c0. Report an issue: GitHub.