How to run vi from Symfony Process? How to run vi from Symfony Process? symfony symfony

How to run vi from Symfony Process?


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();    }


Your question makes complete sense by the way..

My thoughts are:

  • You get a Exit Code: 1 --> Which means the file name to edit wasn'tspecified. Although I could be wrong.
  • It shows "Working directory:[path]". Which tells me, maybe the path is missing.
  • Also, I don't know which user (on the system) runs the Symfony Process Component.

So maybe try:

$process = new Process('vi /tmp/temp.file');

Use /tmp because anyone should have access, also possible a web folder that is writable. Another thought, is to run the process with sudo and specify the user vimrc:

$process = new Process('sudo vim -u ~user/.vimrc /tmp/temp.file');

But then you might need to pass input (like sudo password):

$process->setInput('someSudoPassword');

But who's sudo password I don't know. Again, I'm not sure which user runs the Process Component.

These are just some thoughts, and I'm not certain if it solves anything but I hope it might help you, or even help to think about another way to handle this.


Why would you want to do this? vi is something that is controlled by keyboard. If you need to, you might need to check the full path and if php/symfony has access to this path. Probably your php script does not have access to this script, and the web server (I assume you're talking about a web application here) might not be allowed to start a login shell at the server anywhere. Would be great if you could provide more details about your goal + environment.

If you just want to edit / manipulate the file, the sed command might be an option. Or open/manipulate the file directly with php might be even better.