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

报告相同问题?

悬赏问题

  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启