Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

Clear PHP CLI output

I'm trying to get a "live" progress indicator working on my php CLI app. Rather than outputting as

1Done
2Done
3Done

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.

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?

Cheers for the help!

I want to avoid echoing 24 new lines if I can.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try outputting a line of text and terminating it with " " instead of " ".

The " " character is a line-feed which goes to the next line, but " " is just a return that sends the cursor back to position 0 on the same line.

So you can:

echo "1Done
";
echo "2Done
";
echo "3Done
";

etc.

Make sure to output some spaces before the " " to clear the previous contents of the line.

[Edit] Optional: Interested in some history & background? Wikipedia has good articles on " " (line feed) and " " (carriage return)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...