Skip to content

Commit 1b5e8dc

Browse files
committed
Documented setTty and setPty
1 parent 922a469 commit 1b5e8dc

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

components/process.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,35 @@ The input of a process can also be defined using `PHP streams`_::
352352
// will echo: 'foobar'
353353
echo $process->getOutput();
354354

355+
Using TTY and PTY Modes
356+
-----------------------
357+
358+
All examples above show that your program has control over the input of a
359+
process (using ``setInput()``) and the output from that process (using
360+
``getOutput()``). The Process component has two special modes that tweak
361+
the relationship between your program and the process: teletype (tty) and
362+
pseudo-teletype (pty).
363+
364+
In TTY mode, you connect the input and output of the process to the input
365+
and output of your program. This allows for instance to open an editor like
366+
Vim or Nano as a process. You enable TTY mode by calling
367+
:method:`Symfony\\Component\\Process\\Process::setTty`::
368+
369+
$process = new Process(['vim']);
370+
$process->setTty(true);
371+
$process->run();
372+
373+
// As the output is connected to the terminal, it is no longer possible
374+
// to read or modify the output from the process!
375+
dump($process->getOutput()); // null
376+
377+
In PTY mode, your program behaves as a terminal for the process instead of
378+
a plain input and output. Some programs behave differently when
379+
interacting with a real terminal instead of another program. For instance,
380+
some programs prompt for a password when talking with a terminal. Use
381+
:method:`Symfony\\Component\\Process\\Process::setPty` to enable this
382+
mode.
383+
355384
Stopping a Process
356385
------------------
357386

@@ -483,7 +512,6 @@ Use :method:`Symfony\\Component\\Process\\Process::disableOutput` and
483512
However, it is possible to pass a callback to the ``start``, ``run`` or ``mustRun``
484513
methods to handle process output in a streaming fashion.
485514

486-
487515
Finding an Executable
488516
---------------------
489517

0 commit comments

Comments
 (0)