如何执行需要用户输入的系统命令并实时查看输出


How do I execute a system command that requires user input and see the output in real time?

当我运行以下命令并一直提供一个空密码短语时:

mount -t ecryptfs /to/be/mounted /mount/location

:

Passphrase:
Wrong input, non-empty value required!
Passphrase:
Wrong input, non-empty value required!
Passphrase:
Wrong input, non-empty value required!

太好了!但是,当我尝试从PHP脚本中使用以下代码执行相同的操作时:

#!/usr/bin/php
<?php
        system("mount -t ecryptfs /to/be/mounted /mount/location");
?>

:

Wrong input, non-empty value required!
Wrong input, non-empty value required!
Wrong input, non-empty value required!
Passphrase:
Passphrase:
Passphrase:

不太棒了!如何让PHP在正确的时间以正确的顺序显示输出?

也许它涉及到,当PHP作为服务器模块与CGI运行时,system()调用试图在每一行输出后自动刷新web服务器的输出缓冲区。