symfony/process · error · LogicException
Input cannot be set while the process is running.
Error message
Input cannot be set while the process is running.
What it means
setInput() throws this LogicException when called on a process that is already running. The child's stdin is established at start time, so input can only be provided while the process is in a not-yet-started or terminated state.
Solutions
- Call setInput() before start()/run().
- Stop() or wait() for the process to finish before setting new input, then restart if needed.
- Provide all input up front at construction: new Process($cmd, null, null, $input).
- For interactive mid-run input, use a TTY or communicate()/InputStream from the symfony/process stream API.
Example fix
// before
$process->start();
$process->setInput('foo'); // LogicException
// after
$process->setInput('foo');
$process->start(); Defensive patterns
Strategy: validation
Validate before calling
if (!$process->isRunning()) {
$process->setInput($input);
} Try / catch
try {
$process->setInput($input);
} catch (\LogicException $e) {
// running: stop() or wait() first, or feed via InputStream
} Prevention
- Pass input at construction: new Process($cmd, $cwd, $env, $input).
- For interactive stdin, use symfony/process InputStream with start() instead of setInput().
When it happens
Trigger: Calling setInput() after start()/run() while isRunning() is true. Also reachable via constructors that call setInput() with input on a reused/running instance.
Common situations: Streaming data to a subprocess interactively and trying to change stdin mid-run; retry loops reconfiguring a still-running process; fluent builders invoked after start.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Start time is only available after process start.
- Disabling output while the process is running is not…
- Output cannot be disabled while an idle timeout is set.
- Enabling output while the process is running is not…
- Idle timeout cannot be set while the output is disabled.
AI-assisted analysis of symfony/process@99b85026db (2026-09-14).
Data as JSON: /api/errors/18b0833edcb5c1c5.
Report an issue: GitHub.
Appendix: source
Thrown at Process.php:1197
{
return $this->input;
}
/**
* Sets the input.
*
* This content will be passed to the underlying process standard input.
*
* @param string|resource|\Traversable|self|null $input The content
*
* @return $this
*
* @throws LogicException In case the process is running
*/
public function setInput(mixed $input): static
{
if ($this->isRunning()) {
throw new LogicException('Input cannot be set while the process is running.');
}
$this->input = ProcessUtils::validateInput(__METHOD__, $input);
return $this;
}
/**
* Performs a check between the timeout definition and the time the process started.
*
* In case you run a background process (with the start method), you should
* trigger this method regularly to ensure the process timeout
*
* @throws ProcessTimedOutException In case the timeout was reached
*/
public function checkTimeout(): void
{
if (self::STATUS_STARTED !== $this->status) {View on GitHub (pinned to 99b85026db)