Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run vi from Symfony Process?

I have the following code:

        $process = new Process('vi');

        try {
            $process->setPty(true);
            $process->mustRun(function ($type, $buffer) {
                echo $buffer;
            });
            //echo $process->getOutput();
        } catch (ProcessFailedException $e) {
            echo $e->getMessage();
        }

However, it dies for me with the following info:

The command "vi" failed.

Exit Code: 1(General error)

Working directory: [path]

Output:
================
Vim: Error reading input, exiting...
Vim: Finished.


Error Output:
================
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

UPDATE

Seems it was not clear for some people what I'm going to do. I will explain. This script is being run in console. The same thing works via passthru (although Vim still warns about the output). I want to have an interactive process that will allow users to modify some file before its sent somewhere. I do not want to implement my own editor and that's why I want them to use vi. vi is available on my server (it is clearly visible from the output I provided).

like image 314
Denis V Avatar asked Aug 04 '16 10:08

Denis V


1 Answers

Here I was given a proper answer: https://github.com/symfony/symfony/issues/19528

Basically, I had to use $process->setTty(true). So, the full example will be:

    $process = new Process('vi');

    try {
        $process->setTty(true);
        $process->mustRun(function ($type, $buffer) {
            echo $buffer;
        });
    } catch (ProcessFailedException $e) {
        echo $e->getMessage();
    }
like image 189
Denis V Avatar answered Sep 30 '22 04:09

Denis V