Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Capture Console Output  RSS feed

 
Amir Iqbal
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THE PROBLEM:

i have an IDE (eg say MYECLIPSE or NETBEANS) when we execute a class then the console of the IDE open ups and
output of the class appears in IDE's console. so is it possible to get that string (i-e the output) in some file
or you may say capture the output. if yess than how???
please do tell me.

all kinds of suggestions and solutions are warmly welcome.

Thanks in advance.

REGARDS
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the command line: use > to redirect the output, and 2> to redirect the errors. You can use both:

and even redirect one to the other:

The first redirects the output to file "out" and the error to the output.
The second redirects the error to file "err" and the output to the error.

Note that you will need to put the redirecting from one stream to the other at the end or it will still have two different streams.


From code you can use System.setOut and System.setErr for this.
 
Amir Iqbal
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your Reply.
but the problem is your option works manually. but what if i want to automate the code.
means i want to redirect output Automatically.

Regards
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read my last sentence?
 
Sev Zaslavsky
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, you're suggesting that Amir change his code to redirect System.setOut and System.setErr to a file on disk?

Amir, it seems you are looking for a way to echo the IDE console output to a file? In that case you're looking for some kind of setting in Netbeans or Eclipse?
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sev Zaslavsky:
Rob, you're suggesting that Amir change his code to redirect System.setOut and System.setErr to a file on disk?

And why not? It's only for the current JVM instance. Sure it will be slower than printing to the default output and error streams, but there should be no harm.

I'd still go for shell induced redirecting, but that's another story.
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we're talking about starting code from the "Run" menu in Eclipse, then the Common tab of the Run Configurations dialog box lets you redirect output to a file. I don't use NetBeans so I can't help there.
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the System.setOut() and System.setErr() methods does not do any harm at all. In fact, that's sort of the way Eclipse get the output of a program started via its Run button into its own console window ... you can even temporarily change the System.out and System.err streams, store references to the original ones in some variables and change them back to original again later. This is somewhat useful for sending, say, the console output of a specific method to some file, while not sending there the output of the whole program.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!