doucai7294 2016-08-04 10:21
浏览 54
已采纳

如何从Symfony Process运行vi?

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).

  • 写回答

3条回答 默认 最新

  • doutou7961 2016-08-04 20:05
    关注

    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();
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?