更新时间:2022-02-21 01:52:49
其他时间,我遇到了与您相同的问题.如果在终端上执行同一行,则结果是相同的,因此这不是php问题,而是shell问题:
I've come across the same problem as you with read
other times. If you execute the same line on the terminal, the result is the same, so this is not a php issue, but a shell issue:
$ echo 'Foo' | read -p 'Enter your name : ' x; echo "Your name is : $x"
Your name is :
如果将read
包裹在while .. do .. done
内,那么它们都可以完美运行:
If you wrap the read
inside a while .. do .. done
, then it all works perfectly:
$ echo 'Foo' | while read -p 'Enter your name : ' x; do echo "Your name is : $x" ; done
Your name is : Foo
我不知道为什么会这样.
I don't know why this happens though.
此外,您可以尝试使用 proc_open
和类似的方法,您将获得对输入/输出流,但是我不知道它们是否可以解决read
问题.
Also you can try using proc_open
and similar, and you'll get more control of the input/output streams, but I don't know whether they will work with the read
issue.