• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clearing STDOUT  RSS feed

 
Jim Longmore
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

First time post, hoping someone can help me.

Is there a way to clear the standard out(i.e System.out) of everything, and start anew with a blank console? I tried System.out.flush() but it didn't do anything useful.

Awaiting a reply
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't and you shouldn't do it even if there were.

You don't own the screen, you should never assume you have exclusive access to it.
If you want something you can control, use a Swing GUI instead or write to a file.
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.flush() does, actually, do something useful — or at very least it should. it should make sure that everything you've written to it so far has actually been displayed on screen (or written to file, or wherever System.out goes today) before the .flush() finishes.

if System.out goes to a screen, there are ways to clear it. the most obvious one is to write a long string of newlines to it, so that everything else scrolls off the top. but users who have seen user interfaces designed after, oh, 1980 or so, are prone to laugh at tricks that crude...

the other ways to clear it depend on a number of assumptions: that System.out goes to a screen, that you have the user's permission to hog it, and that it's some one particular kind of screen. if you can safely assume those things, you can go googling for "ANSI escape sequences", or perhaps even "Java curses". but you should think long and hard about those assumptions before you take them for granted.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Longmore:
Hi all.

First time post, hoping someone can help me.

Is there a way to clear the standard out(i.e System.out) of everything, and start anew with a blank console? I tried System.out.flush() but it didn't do anything useful.

Awaiting a reply


System.out doesn't necessarily go to a console. In Unix, and even in DOS, you can redirect stdout to a file or just about any device that accepts output. In such a situation, what does it mean to "clear standard out"? It isn't clear to me what such an operation would do if, for instance, stdout was redirected to the lpr. This one reason that the standard Java API doesn't have this built in.

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!