React composer.phar questions with php exec ()

I think the title is a bit vague. But my English is not very good, so I miss the best.

I am currently writing a tool that also executes .phar composer from source.

Therefore, when installing some stuff with composer.phar, sometimes a question arises and additional input is required, such as the desired format or simple questions on Y / N.

When I use exec () it seems like these questions are impossible to respond to.

So, I was wondering how can I achieve this with PHP.

Any ideas?

Update To show a simple example, I do the following:

exec("php /Users/johannesklauss/Development/web/composer.phar create-project symfony/framework-standard-edition /Users/johannesklauss/Development/web/Symfony 2.1.x-dev");

      

The problem is that composer is in and asks if he should keep version control history:

Do you want to delete existing VCS history (.git, .svn ..)? [Y, N]?

So I need to enter y

or n

into the console. But this is not possible with exec. So I need some kind of interactive mode or what.

+3


source to share


1 answer


One word of caution: look for flags that you can send to the original command to "auto-reply". You have no real guarantees as to what question the composer of .phar will ask, or the order that it will ask them. It should be seen as a "hack" and the normal response in our brain should be applied with all this caveat and context and so on.

Anyway, I think you will need proc_open () , which allows you to start a process and access stdin and stdout to do so. See Example Code # 1 on this page of the doc, this is very close to what you are likely to need.



Once you have access to the stdin / stdout resources for a process, you can read / write to them however you like. The good news is that this will allow you to "read" the prompt and in LEAST double check that it is asking what you expect from it (and for example, throw an exception if you don't recognize the prompt)

+2


source







All Articles