清除PHP CLI输出 [英] Clear PHP CLI output
问题描述
我正在尝试在我的PHP CLI应用程序上运行一个实时"进度指示器.而不是输出为
I'm trying to get a "live" progress indicator working on my php CLI app. Rather than outputting as
1Done
2Done
3Done
我希望它清除并仅显示最新结果. system("command \ C CLS")不起作用.也没有ob_flush(),flush()或我发现的其他任何东西.
I would rather it cleared and just showed the latest result. system("command \C CLS") doesnt work. Nor does ob_flush(), flush() or anything else that I've found.
我正在运行Windows 7 64位旗舰版,我注意到命令行输出是实时的,这是意外的.每个人都警告我说,不会...但是可以... 64位特权吗?
I'm running windows 7 64 bit ultimate, I noticed the command line outputs in real time, which was unexpected. Everyone warned me that out wouldn't... but it does... a 64 bit perk?
为帮助喝彩!
如果可以的话,我想避免回显24行.
I want to avoid echoing 24 new lines if I can.
推荐答案
尝试输出一行文本,并以"\ r"而不是"\ n"结尾.
Try outputting a line of text and terminating it with "\r" instead of "\n".
"\ n"字符是换行符,可转到下一行,而"\ r"只是将光标返回到同一行的位置0的返回.
The "\n" character is a line-feed which goes to the next line, but "\r" is just a return that sends the cursor back to position 0 on the same line.
因此您可以:
echo "1Done\r";
echo "2Done\r";
echo "3Done\r";
等
请确保在"\ r"之前输出一些空格,以清除该行的先前内容.
Make sure to output some spaces before the "\r" to clear the previous contents of the line.
可选:对某些历史感兴趣背景? Wikipedia在"\ n"(换行)和
这篇关于清除PHP CLI输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!