如何从Symfony Process运行vi?

Den*_*s V 7 php symfony symfony-process

我有以下代码:

        $process = new Process('vi');

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

但是,它通过以下信息为我而死:

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

似乎某些人不清楚我将要做什么.我会解释.此脚本正在控制台中运行.同样的事情通过passthru工作(虽然Vim仍然警告输出).我希望有一个交互式进程,允许用户在发送某个文件之前修改它.我不想实现自己的编辑器,这就是我希望他们使用vi的原因.vi在我的服务器上可用(从我提供的输出中可以清楚地看到).

Den*_*s V 6

在这里我得到了正确的答案:https : //github.com/symfony/symfony/issues/19528

基本上,我不得不使用$process->setTty(true)。因此,完整的示例将是:

    $process = new Process('vi');

    try {
        $process->setTty(true);
        $process->mustRun(function ($type, $buffer) {
            echo $buffer;
        });
    } catch (ProcessFailedException $e) {
        echo $e->getMessage();
    }
Run Code Online (Sandbox Code Playgroud)