在收到程序输出时将其打印到网页
老实说,我不知道以前是否有人问过这个问题,或者类似的问题。这样的事情很难搜索。
那么,就这样吧。我希望我的网页运行托管在服务器上的程序(PHP 是正确的选择,是吗?),然后使用该程序的输出打印到网页。但是,该程序不会立即打印所有输出,因此,当我之前尝试过此操作时,它会等到程序成功退出后再打印输出,而不是在收到时打印它。 (这是有道理的)
当返回每个新结果时,如何将输出打印到网页?也就是说,在显示网页之后,当程序输出文本行时,将条目添加到 div 中。
阿贾克斯? JavaScript?我只是在寻找解决此问题的正确方法,而不是代码。
I honestly have no idea if this question has been asked before, or something similar like it. It's hard to search on such a thing.
So, here goes. I would like my webpage to run a program (PHP would be the correct choice here, yes?) hosted on the server, and then use the output of that program to print to a webpage. However, the program doesn't print its output all at once, thus, when I've tried this before, it waits until the program exits successfully before printing output, rather than printing it as it is received. (Which makes sense)
How would one go about printing output to the webpage as each new result is returned? That is, after displaying the webpage, have entries be added to a div as the program outputs lines of text.
Ajax? Javascript? I'm just looking for what the be the correct way to go about this, not code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就个人而言,我会使用三个文件来完成此操作:
我的工作流程如下:
Personally, I would do this with three files:
My workflow would be as follows:
基本思想是打开一个到子进程的管道并从中读取,就像它是一个文件一样。
特别是对于 PHP,请查看 proc_open。
The basic idea is you open a pipe to the child process and read from it as if it were a file.
For PHP in particular, take a look at proc_open.