Capture System.err
how do i capture System.err so i can do with it as i will?
on an actual phone, you dont, you use some kind of Logger, or you can use the netbeans+bluetooth+sonyericsson tools to view the system.out/system.err outputs on a live device
Similar Messages
-
How to capture System.err and System.out in a method?
Is there some way to capture everything that is sent to System.err or System.out and have it instead go to e.g. a method as a String?
The reason I want to do is this: I am invoking some method from a class that sends output to System.err and System.out but while that method is run, I want everything that goes to System.out or System.err to instead go to a String buffer or a Swing Scroll Pane.
What is the easiest way to do this?I want everything that goes to System.out or System.err to instead go to a String buffer or a Swing Scroll Pane.Then maybe you should be searching (and then posting) in the Swing forum. Thats where I've seen this question asked and answered many times in the past.
-
Capturing System.out messages
Hey all,
Just wondering what the easiest way to capture System.out messages of a process, and store these messages in an Array, Vector, or a Buffer where I could read these messages line by line later?
Basically one process System.out.println()'s information I need to use as a variable for a second process. Any help would be greatly appreciated.
Thanks!Here is a class which redirects standard out and err to a JscrollPane.
import java.io.*;
import javax.swing.*;
public class EOutputConsole extends JScrollPane {
Object lock = new Object();
final JTextArea text = new JTextArea(10,30);
PrintStream consoleOut;
public EOutputConsole() {
setViewportView(text);
setupOutput();
* An extention of PrintStream that notifies a lock
* as it's executing its write method. This tells
* an output console that it has input ready.
class ConsolePrintStream extends PrintStream {
Object lock;
public ConsolePrintStream(Object lock, OutputStream out) {
super(out);
this.lock = lock;
public void write(byte[] buf,
int off,
int len) {
synchronized(lock) {
lock.notify();
super.write(buf,off,len);
* A class that extends PrintStream to throw away all
* input sent to it. This is used to supress standard out
* and speed up test model runs with debugging output
class NullPrintStream extends PrintStream {
public NullPrintStream(OutputStream out) {
super(out);
public void write(byte[] buf,
int off,
int len) {
public void suppressStandardOut() {
// create a dumby temp file to use as an output stream
// nothing will ever actually be written to the file
try {
File dumbFile = File.createTempFile("notme", "not1337");
dumbFile.deleteOnExit();
PrintStream out = new NullPrintStream(new FileOutputStream(dumbFile));
System.setOut( out );
System.setErr( out );
} catch(IOException ioe) {
System.out.println("Error supressing standard out");
ioe.printStackTrace();
public void availableStandardOut() {
System.setOut( consoleOut );
System.setErr( consoleOut );
private void setupOutput() {
Thread printer = new Thread( new Runnable() {
public void run() {
PipedInputStream pipe = new PipedInputStream();
BufferedReader in = new BufferedReader
(new InputStreamReader( pipe ));
try {
PipedOutputStream pipeOut = new PipedOutputStream(pipe);
consoleOut = new ConsolePrintStream(lock, pipeOut);
System.setOut( consoleOut );
System.setErr( consoleOut );
catch (Exception e) {
System.out.println("Failed to create Pipe for System.out");
e.printStackTrace();
return;
try {
for(;;) {
while(!in.ready()) {
synchronized(lock) {
lock.wait();
text.append(in.readLine()+"\n");
verticalScrollBar.setValue(verticalScrollBar.getMaximum());
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
printer.setDaemon(true);
printer.start();
} -
Exceptions .. redirecting System.err
I've redirected System.err to a custom class that extends OutputStream.
I have a couple of questions which someone in here might know the answer to:
1. When I receive an exception write(byte b[], int off, int len) is called. The array of bytes is always 8192 long - padded with \x0000 at the end. Why?
2. How do I know an exception has ended? I want to notify the user when it has ended (with a popup). But write() is called for each line, and flush() doesn't seem to be called at all.
Best regards,
BjornDepends what kind of a program you are writing. If you are doing a standalone application, you can always have a master try-catch block in the main() method that will catch Throwable. Nothing should make it past that.
Now, if you are doing a servlet or EJB, you don't want to trap every exception because the container is supposed to receive and handle them for you (thread death, out of memory, etc.) If you have a front-controller pattern implemented, you can put a master try-catch block there and do something like the following:
try {
// implement cool functionality here
catch (RuntimeException e) {
// use code to retrieve stack trace
throw e;
catch (Exception e) {
// use code to retrieve stack trace
// handle exception in application-specific manner
catch (Error e) {
// use code to retrieve stack trace
throw e;
The cool "feature" about exceptions is that they propogate. So, if you don't have the appropriate catch block, it will move to the previous caller. Hence, you can have a master exception processor if either a) you re-throw exceptions on to be procsesed by the master exception processor or b) you don't handle the exception at all and let it propogate naturally.
You also have a number of options so you don't have to rewrite 300 exception try-catch blocks. Subclass Exception, and for all your custom exceptions, put the functionality to dump or store the stack trace there. It will happen anytime your custom exception is instantiated.
Lots of ways to skin a digital cat. However, the argument that you will have to change code to get new functionality is part and parcel of the beast. If you want to capture the stack trace and do something with it, code somewhere will have to change. Either use inheritance, delegation or the exception propogation mechanism inherent to Java to minimize your work.
- Saish
"My karma ran over your dogma." - Anon -
[Feature Request] Seperate tab in log window for System.err
By default, the stack traces of exceptions (and throwables in general) are printed to the System.err stream. So, wouldn't it be useful to include a 2nd tab for System.err messages?
It could be optional to either include or leave out the System.err output in the System.out tab.
The whole idea of this 2nd tab is to set it up like the search output tab: a tree-like list which can be expanded to see the stack trace of each exception that occured during runtime. A small parser can parse the stack trace when an exception is printed on the System.err stream and format it.
If this option would be availble in the debugger only, that would be ok too, I guess. Although, the debugger already has some other means of jumping through code when an exception is thrown (ie, when the debugger 'pauses' runtime).I've logged an Enhancement request to improve the handling of System.err messages (2811508). There are ways to enhance the treatment of System.err messages without introducing a new tab, through the use of color, links back to the source code, and collapsing of entire stack traces to a single line (with a button to see the entire trace).
Thanks!
-- Brian -
Captivate 7 is not capturing system audio, and the software has a broken link
The Problem:
Captivate 7 is not capturing system audio. When I start a screen recording, the line with "System Audio" and its checkbox are eternally grayed out. Next to the grayed out words is a link that says, "Why is this disabled?"
The lnik goes to: http://www.adobe.com/go/cpaudio
Which is not a valid link, so Adobe's site redirects me to blogs.adoble.com/captivate which is ZERO help. Both browsing and the search bar bring no answers.
The Device:
Apple Macbook Air, Mid 2013, running OSX 10.9.2.
What I've done already:
Obvsiously I have set Captivate 7's preferences to capture system audio, and have set System Settings -> Security and Privacy -> Privacy -> Accessibility to allow Captivate to control my computer.
I have also tried clicking the Mic icon, Selecting Source with the System Audio icon and that doesn't record system audio either. It acts like it is recording system audio, but when I stop recording I get a popup that says, "Cannot record system audio. Ensure that you are playing audio on your computer [Okay]"It's a wierd one.
One thing to try, and this fixes a lot of things, trash your preferences.
http://www.digitalrebellion.com/prefman/
DM -
How to capture System.out, done by another program
Hi All,
My application runs other application in back. How can I capture system.out.println() written by another application & display via dialog box.
Like :execl() or execv() function in C runtime library. Where every printf() message printed to passed buffer.
Thank you,
Avin PatelYou can create an InputStream from a started process. Then read all the bytes from the inputstream and write them to an outputstream (like System.out)
Process p = Runtime.getRuntime().exec(COMMAND);
InputStream is = p.getErrorStream(); //Or another stream
int[] buffer = new int[128];
while((read = is.read(buffer)) != -1){
System.write.out(buffer, 0, read);
} -
Passing System.out/System.err as parameters
I'm sure there must be a simple answer to this that I'm just not seeing, suggestions please.
I have a method in a logging utility that takes either a PrintWriter or a Printstream parameter as a target for logging and a second method that closes the log.
In principle either System.out or System.err could be passed in either directly or wrapped in a PrintWriter.
In the closing method I want to determine if one of these two PrintStreams were passed and if so skip the close() operation so as not to lose connectivity to stdout or stderr.
In the case of the PrintStream parameter I can use an identity check and condition a boolean to control closing the file.
The problem is the PrintWriter, if the utility user wraps these PrintStreams.
1: As I understand it closing the PrintWriter will cause the underlying OutputStream to close.
2: Since it's a protected field the underlying OutputStream is not visible to me.
3: I don't wish to subclass PrintWriter if there's another way to solve the problem.
Any ideas?Why don't you use a BufferedWriter() ?
-
Redirecting System.err on a mobile phone?
Hi,
Is there a way of redirecting System.err? Unfortunately, System.setErr does not exist in MIDP, so I haven't been able to write my own PrintStream to replace err.
I need to know what the output of Exception.printStackTrace() is at a certain point. There is certainly a way of accessing System.err, otherwise it wouldn't be present in MIDP ... .
Thanks!
StefanHi
J2ME Polish provides a logging framework, which offers different logging levels and the ability to view logging messages on real devices.
Mihai -
System.out and System.err
Hi all,
This is a stupid newbie question, but I could not find the answer on the Web
site, so here goes: Where do System.out and System.err get written to? I'm
trying to deploy some plain-vanilla stateless session beans that do a bunch
of println() calls, but I can't see the output anywhere! The WebLogic
Console shows no messages, /myserver/weblogic.log has nothing interesting,
and there are no .log files anywhere that I can see. I even searched /tmp
and found nothing of interest. What am I missing? Do I have to explicitly
open a file for System.out and/or System.err? That doesn't sound right...
- danzThe simple answer to your questions are no and no.
I recently logged a problem with BEA WebLogic technical support regarding
this issue and their response is:
You have two choices. You can either use standard Java file i/o to write
your output to a file, or you can use our t3loggingservices to append
messages into the weblogic.log
The "jump point" for the logging services is at --
http://www.weblogic.com/docs51/classdocs/javadocs/weblogic/common/LogService
sDef.html
It is actually very easy to use -- after you import the proper packages into
your web application it is just as easy to use as System.out.println.
John J. Feigal Voice (651)766-8787 (main)
Sr. Technical Consultant (651)766-7249 (direct)
Ensodex, Inc. Fax (651)766-8792
4105 N. Lexington Ave., Suite 150 email [email protected]
Arden Hills, MN 55126 WebSite http://www.ensodex.com
"Jon Wynett" <[email protected]> wrote in message
news:[email protected]...
I'm running WebLogic as an NT Service. Is there any way to see the
System.out.println messages? Can they be redirected to the weblogic.log
file?
We were running through a DOS Window and saw all the messages, however we
ideally want to run Weblogic as a service.
"Rob Woollen" <[email protected]> wrote in message
news:[email protected]...
I'm guessing that you started the server with the .exe file on Windows.
If you're debugging with printlns, it's generally more conventient to
use the startWebLogic.sh or startWebLogic.cmd files to start the server
from a shell.
By default, you'll see stdout and stderr in the window.
-- Rob
Dan Zivkovic wrote:
Hi all,
This is a stupid newbie question, but I could not find the answer on
the
Web
site, so here goes: Where do System.out and System.err get written to?I'm
trying to deploy some plain-vanilla stateless session beans that do abunch
of println() calls, but I can't see the output anywhere! The WebLogic
Console shows no messages, /myserver/weblogic.log has nothinginteresting,
and there are no .log files anywhere that I can see. I even searched/tmp
and found nothing of interest. What am I missing? Do I have toexplicitly
open a file for System.out and/or System.err? That doesn't soundright...
- danz -
Using System.err.println() from within the classes of WAS ?
hi,
I am using admin.jar,a jar file which is being used by Web Application Server in my own class.
I am referencing some of the classes from admin.jar from my class.
I tried to print some trace statements,using System.err.println() from within the classes in admin.jar but they did not reflect in defaulttrace0.trc.
I made these changes in the admin.jar being used by WAS.
I restarted the server and even restarted the machine but without success.
I want to know how to print System.out.println() statements from within the classes in admin.jar.
Also, am i looking for these statements in the right file for eg. defaulttrace0.trc. or is it some other file that i need to look into.
I need urgent help on this.
Reward points assured.
thanks a lot.
Sauravthanks craig,
ur answer has helped me a lot.but it didnt quite help me.
nevertheless i am trying to set different levels of severity.
Is there anything else that i can do.
Also,i commented out a line of code today in one of the class DataSourceManagerImpl.java in sapj2eenginedeploy.jar
for eg. temp.delete in it deploy method.Buth that line still executed.
I m totally lost as to wht to do.
I m trying to create a datasource from my application in WAS.For that i m using the WAS APIs.But its not working completely.
I am using the above jar and its method createdatasource.
I am callin it from my application's class.
It creates a datasource and i can see it in JDBC Connector list in Visual Administrator.But it appears with red sign meaning its not started.When i start it from the tool then it starts.
But in defaulttrace.trc file it shows an error "FileNotFindException". This happens,and i am very much sure, in the deploy() of DataSourceManagerImpl.java class of sapj2eenginedeploy.jar.
i want to apply println inside this method so i may know where exactly i ma getting the error and get so more info so i may solve my problem.
pls help me.
its really urgent.
thanks again
saurav -
One JVM with different system.out / system.err files
I have a menu application which allows me to launch different swingapps which runs inside one single JVM.
All applications have their own properties.file which is read and handled at the start of each application.
One property allows me to print all kind of system.err / system.out which i want to redirect to a specific file. This is implemented with following code:
if (isTRACE_ENABLED()){
try {
setTrace_out_log(new PrintStream(
new BufferedOutputStream(
new FileOutputStream(props.getProperty("TRACE_OUTLOG_FILE")),128), true));
System.setOut(getTrace_out_log());
setTrace_err_log(new PrintStream(
new BufferedOutputStream(
new FileOutputStream(props.getProperty("TRACE_ERRLOG_FILE")),128), true));
System.setErr(getTrace_err_log());
} catch(IOException e) {
e.printStackTrace();
}This works file but... all system.out and system.err is redirected to same file... which is not what i want.
Example:
debug property for menu application = enabled
debug property for app 1 = disabled
debug property for app 2 = enabled
In above case i want to have 4 new files:
- menuapp_out
- menuapp_err
- app2_out
- app2_err
This doesn't work, the files are created but after starting app2, the print-statements for the menu application are alse redirected to the app_2_xxx files. And when i finish app2, i do not get any print-output anymore
IMHO this is because the JVM only has 1 system.out and 1 system.err file. Is there some way to solve this?I understand that i need to use java.util.logger (JUL) or Log4j
Are there any (free) tools availabe to read/analyze the logfiles created by above tools? -
Redirecting System.err to a JOptionPane
Hello,
I tried to write a piece of code which shows all exceptions in a JOptionPane instead of the console. But I meet two difficulties:
1. I don't know how to detect the line count of the error message (so that currently I have to display the optionPane for each error line, which is unacceptable).
2. I receive more error messages than expected. The produced parse error gives 5 lines on a console, but here I receive 60.
What's wrong?
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
class Redirecting extends JFrame {
public Redirecting() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,300);
JTextAreaOutputStream err= new JTextAreaOutputStream();
System.setErr(new PrintStream(err));
JButton b= new JButton("Produce error");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.out.println(Integer.parseInt("1"));
System.out.println(Integer.parseInt("2"));
System.out.println(Integer.parseInt("Error"));
add(b, BorderLayout.SOUTH);
setVisible(true);
public static void main(String[] args) throws Exception {
EventQueue.invokeLater(new Runnable() {
public void run() {
new Redirecting();
class JTextAreaOutputStream extends OutputStream {
int icnt=0;
private JTextArea area;
public JTextAreaOutputStream() {
area= new JTextArea();
public void flush() throws IOException {
JOptionPane.showMessageDialog(Redirecting.this, area, "Error",
JOptionPane.ERROR_MESSAGE);
// area.setText("");
public void write(byte b[]) throws IOException {
area.append(new String(b));
public void write(byte b[], int off, int len) throws IOException {
System.out.println(icnt++);
String s = new String(b , off , len);
area.append(s);
flush(); // to make error lines visible
public void write(int b) throws IOException {
area.append(String.valueOf(b));
}maybe this ?
* recieving error for testing
* @param e
protected void bt_generateError_actionPerformed(ActionEvent e) {
DateFormat fo = new SimpleDateFormat("mm.dd.yyyy");
try {
// Here reciev parsing error
fo.parse("sacascsa");
} catch (ParseException e1) {
String exception = Util.formateException(e1.getStackTrace());
// show error
Util.showException(frame, exception);
* utilita
* @author Dima
public static class Util {
* formateException formating error in way you want
* @param stack
* @return
public static String formateException(StackTraceElement[] stack) {
String formatedException = "";
for (int i = 0; i < stack.length; i++) {
System.err.println(stack.getClassName() + ""
+ stack[i].getMethodName() + "" + stack[i].getClass()
+ " Line" + stack[i].getLineNumber());
formatedException = formatedException.concat(
stack[i].getClassName()
+ "."
+ stack[i].getMethodName()
+ " "
+ stack[i].getClass()
/** + " Line" + stack[i].getLineNumber() */
+ "\n"); // remove comment and recieve errors line
// numbers
return formatedException;
* showException return JOptionPane with formatted error
* @param com
* @param exceptionText
public static void showException(Component com, String exceptionText) {
JPanel canva = new JPanel();
canva.setMinimumSize(new Dimension(300, 200));
canva.setPreferredSize(new Dimension(300, 200));
JTextArea area = new JTextArea();
area.setText(exceptionText);
JScrollPane pan = new JScrollPane();
pan.getViewport().setView(area);
canva.setLayout(new BorderLayout());
canva.add(pan);
JOptionPane.showMessageDialog(com, canva, "Error Title",
JOptionPane.ERROR_MESSAGE); -
Redirecting System.err to a TextArea
Hi there !
I want to redirect the output of System.err to a TextArea.
System.err is everywhere in my project. Is there any simple way to just redirect the output of this err to some TextArea?
Thanks in Advance
DexterSee the API java.lang.System.setErr()You will then need to start a thread to read from the PrintStream and put the
output in your text area.
- ajay -
How do I redirect System.err output in iPlanet 4.1?
All,
I've been trying for days to redirect System.err output from a Java program
to a log file. I followed the instructions here:
http://knowledgebase.iplanet.com/ikb/kb/articles/4790.html
Unfortunately, nothing has been written to any of the log files (even though
I have plenty of System.err.println()'s in my code).
Anyone else get this to work correctly?
Thanks in advance,
--BillHi,
What is the product web server or application server ? If it is application
server then I'm very sure that this output will be seen in the kjs log file in
Unix and in the command window in Windows NT/2K, only if you have allowed the
process to interact with desktop. Please let me know if this answers your
question for me to help you further on this.
Regards
Raj
"news.uswest.net" wrote:
All,
I've been trying for days to redirect System.err output from a Java program
to a log file. I followed the instructions here:
http://knowledgebase.iplanet.com/ikb/kb/articles/4790.html
Unfortunately, nothing has been written to any of the log files (even though
I have plenty of System.err.println()'s in my code).
Anyone else get this to work correctly?
Thanks in advance,
--Bill
Maybe you are looking for
-
no link to open access to the internet. I used Yahoo Messenger, clicked on the 'mail icon' and since Firefox is my default it opened and I was able to continue from there. If I try to click File, open New Page, I get the "problem loading webpage" and
-
Something about two fact table in one subject
Hi all, when I using two fact table in one subject, it can't make sense as expected. The problem is describled as follows: 1.about the RPD: In the presentation layer of Admin Tool, there is a mesure names "A", which is equal to B*C, come from table t
-
MAC Desktop software and Blackberry 9900 OS7
I am not sure if it is justy me but having huge synch problems with my new 9900. The orginal format of the BB software have options to the left of the screen for Calendar, contacts, tasks and notes. This does not appear anymore as with my previos B
-
Frequency of dead combo drives
Hi there, I wonder how frequent is the occurance of combo drives not able to record in new ibook G4s? I bought my new machine and never used the cd writing part for over a year or so. But when I used it (or tried to use it) it did not work. I wonder
-
Load Balancing - BSP Applications
Hi All, Our current system has lot of custom BSP Applications. Recently the basis/network teams have taken up load balancing activities to better manage the workload. We have observed after the load balancing activity came into play that our BSP call