Skip to content

Commit d8df410

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: Documented setTty and setPty
2 parents eb3accd + febadda commit d8df410

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

components/process.rst

+29-1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,35 @@ The input of a process can also be defined using `PHP streams`_::
358358
// will echo: 'foobar'
359359
echo $process->getOutput();
360360

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

@@ -513,7 +542,6 @@ Use :method:`Symfony\\Component\\Process\\Process::disableOutput` and
513542
However, it is possible to pass a callback to the ``start``, ``run`` or ``mustRun``
514543
methods to handle process output in a streaming fashion.
515544

516-
517545
Finding an Executable
518546
---------------------
519547

0 commit comments

Comments
 (0)