如何使用PHP在linux中调用另一个CLI.exe进程I / O?
I have a CLI.exe developed by mono and want to control it by PHP. My idea is let the CLI keep readline as its input, after this, we can get a PID of this CLI. Next, Let PHP scripts send commands to this CLI as CLI's input via PID(or something else). But I don't know if there's any PHP func can do this or how. Any help is appreciate!
我有一个由mono开发的CLI.exe,想要通过PHP控制它。 我的想法是让CLI 保持readline作为输入,在此之后,我们可以获得此CLI的PID。 下一步,让PHP脚本通过PID(或其他)将命令发送到CLI作为CLI的输入。 但我不知道是否有任何 PHP函数可以做到这一点或如何。 任何帮助都很感激! p> div>
If you want to communicate with the process via STDIN/STDOUT, you'll need to spawn it from PHP using proc_open, which gives you access to these pipes.
To more closely match what you ask, I'd suggest named pipes or unix sockets. If your CLI.exe is the parent, it would use the mkfifo system call to create the named-pipes. PHP has some good documentation here.
Another alternative on *nix platforms is Unix Domain Sockets. Typically these are files named with the .sock extension under the /var/run folder (or subdirs).