douhao123457 2013-02-17 17:26
浏览 112
已采纳

too long

The title is a little vague, I believe. But my english's not good, so I'm lacking of an better one.

I'm currenty writing a tool that also executes the composer.phar from the source code.

So when installing some stuff with composer.phar it sometimes asks questions and wants additional input, like desired format or simples Y/N questions.

When I use exec() it seems that it's not possible to react to those questions.

So I wondered how I can achieve this with PHP.

Any ideas?

Update To show an simple example, I do this:

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

Problem here is that the composer at the and asks if it should keep the version control history:

Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]?

So I need to type in y or n to the console. But that's not possible with exec. So I need some interactive mode or what.

  • 写回答

1条回答 默认 最新

  • dsfjk44656 2013-02-17 17:39
    关注

    One word of caution: look for flags you can send to the initial command to "auto answer". You have no real guarantees about what question composer.phar will ask or the order it will ask them. It should be considered a "hack" and the normal reaction in our brains should apply with all it's caution and context, etc...

    Anyway, I think what you'll need is proc_open(), which let's you start a process and have access to the stdin and stdout for it. See the Example #1 code on that doc page, it's very close to what you likely need.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)