开发者

How to respond to prompts from a process spawned with `exec`?

开发者 https://www.devze.com 2023-02-16 07:12 出处:网络
I need to execute a series of commands on the OS from my PHP script. One of the commands, after being executed, prompts the use开发者_如何学Gor to enter a password, then enter password again (to verif

I need to execute a series of commands on the OS from my PHP script. One of the commands, after being executed, prompts the use开发者_如何学Gor to enter a password, then enter password again (to verify the first input). How do I respond to these prompts from PHP?


You can't directly do that with exec. You can do it by using proc_open instead; be sure to read the examples and comments to avoid some common pitfalls.

Of course, possibly in your specific case maybe the problem can be circumverted by writing a shell script that feeds predetermined input into the spawned process's STDIN instead; this could end up being simpler, if not as "pure".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号