AJAX进度:从Shell读取输出 [英] AJAX Progress: Reading output from the Shell

查看:319
本文介绍了AJAX进度:从Shell读取输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:制作进度栏,用户可以在其中检查我的服务器下载了多少文件。



方案:我有一个PHP脚本通过popen执行一个python脚本。我这样做:

  $ handle = popen('python last','r'); 

$ read = fread($ handle,4096);

pclose($ handle);

这个python脚本输出到shell类似这样:

  [last] ZVZX-W3vo9I:正在下载视频网页
[最后一页] ZVZX-W3vo9I:提取视频信息
[download]目的地:myvideo.flv
[下载] 3.30M / s ETA时的10.09M的9.9%00:02

问题:当我在shell输出生成的文件中读取时,得到除最后一行之外的所有shell输出! WHY?



只是为了添加,当我通过shell运行命令时,shell游标出现在该行的末尾,并等待脚本完成。 p>

感谢所有

解决方案

我想到的第一件事:程序检测到它没有在TTY上执行,因此不显示最后一行,这可能涉及丑陋的控制字符,因为该行似乎更新本身?



当你将输出重定向到一个文件(在shell中),或者通过更少管道?如果你没有看到最后一行,可能是这种情况。我不知道另一个解决方案,而不是修复源。


Objective: Make a progress bar where users can check how much of a file has been downloaded by my server.

Scenario:I have a PHP script that executes a python script via popen. I have done this like so:

$handle = popen('python last', 'r');

$read = fread($handle, 4096);

pclose($handle);

This python script outputs to the shell something like this:

[last] ZVZX-W3vo9I: Downloading video webpage
[last] ZVZX-W3vo9I: Extracting video information
[download] Destination: myvideo.flv
[download]   9.9% of 10.09M at    3.30M/s ETA 00:02

Problem:When I read in the file generated by the shell output I get all the shell output except the last line!? WHY?

Just to add, when I run the command via the shell, the shell cursor appears at the end of that line and waits till the script is done.

Thanks all

解决方案

First thing that comes into my mind: maybe the program detects that it is not executed on a TTY and therefore does not show the last line, which probably involves ugly control characters because that line seems to update itself?

What happens when you redirect the output to a file (in the shell), or pipe it through less? If you don't see the last line there, this is likely to be the case. I don't know of another solution than to fix the source.

这篇关于AJAX进度:从Shell读取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆