Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 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 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...