Redirecting stdout and stderr to GUI

Hello,
Is it possible to redirect System.out and System.err output to a JTextArea or a JLabel? This output will be coming from another class that is instantiated from within my GUI class.
Any suggestions or otherwise would be appreciated,
Thanks.

you need to define a PrintStream for it.
suggest you write a class extending OutputStream and in the flush() method include the writing to the text area.
MyOutStream outStream = new MyOutStream();
PrintStream ps = new PrintStream(outStream.getOutStream(), true);
System.setErr(myPrintStream);
System.setOut(myPrintStream);
can get messy mind you.
hope this points you in some useful direction.
Takis

Similar Messages

  • Redirecting stdout and stderr when starting a MS with the NM

    We are looking at using the Node Manager for stopping and starting the managed servers in some of our projects, to give the testers/developers the ability with operator role in the WLS console to save them calling someone.
    The only trouble is, with our existing shell start scripts we redirect shell level stdout and stderr to a file, i.e
    nohup ./startManagedWebLogic.sh test1-ms11 >> $OUTFILE 2>&1 &
    But how do you do the same when starting the same managed server using the node manager and the WLS Admin Console??
    There is the argument "-Dweblogic.log.RedirectStdoutToServerLogEnabled=true", but this only redirects on the JVM level.
    Is there a way around this problem to get the node manager outputing the same as our scripts do.
    Any direction would be great.
    Alistair.

    Gene
    Thanks for the replies and additional information.
    I was almost sure that one of the previously suggested troubleshooting steps would solve the problem but unfortunately that was not the case.
    So, let us look at the following factors....
    1. Delete the Adobe Premiere Elements Prefs file and, if that does not work, then delete the whole 12.0 Folder in which the Adobe Premiere Elements Prefs file exists.
    Local Disk C
    Users
    Owner
    AppData
    Roaming
    Adobe
    Premiere Elements
    12.0
    and in the 12.0 Folder is the Adobe Premiere Elements Prefs file that you delete. If that does not work, then you delete the whole 12.0 Folder in which the Adobe Premiere Elements Prefs file exists. Be sure to be working with Folder Option Show Hidden Files, Folders, and Drives active so that you can see the complete path cited.
    2. Try to open the Premiere Elements 12 Editor from its Adobe Premiere Elements.exe file rather than desktop icon which uses Adobe Premiere Elements 12.exe file.
    Local Disk C
    Program Files
    Adobe Premiere Elements 12
    and in the Adobe Premiere Elements 12 Folder is the Adobe Premiere Elements.exe file that you double click to open the Premiere Elements 12 Editor bypassing the Welcome Screen. If necessary, we could create a desktop shortcut for the Adobe Premiere Elements.exe file for future use to open the program.
    Also, look at the necessity to right click the desktop icon for the program and the .exe files and apply Run As Administrator to each even if you are running the program from a User Account with Administrative Privileges.
    3. Consider creating a new User Account with Administrative Privileges and install and running Premiere Elements 12 in it (I would save this consideration for the last.)
    Please review. We will be watching for the results.
    Thank you.
    ATR

  • Where do my stdout and stderr go?

    I've installed the iPlanet Webserver 6.0SP1 for Solaris.
    I would like to know how could I have the stderr and stdout redirected to log files, in order to be able to see JSP's and servlet's System.out.print() and System.err.print() messages. Now it looks like those messages are completely "lost"... Is it like this?
    Thanks a lot for your help.
    Marco.

    You have to redirect the stdout and stderr when you start the server. So if you normally type
    start
    instead you should type
    start > iPlanet.out
    to put the stdout into the file iPlanet.out
    The syntax for redirecting stderr varies depending on
    what shell you are executing the command in.

  • The stdout and stderr in javaw.exe enviroment

    hi,
    when i run a class using java.exe enviroment,the stdout and stderr is the console,but can someone tell me that where the stdout and stderr in javaw.exe is?
    or javaw.exe don't have stdout and stderr ?
    thanks for your answer

    When you use javaw.exe, whatever you send to stdout and stderr goes to what computer old-timers call the "Bit Bucket". That means it disappears. But you can redirect stdout to a file on your command line if you like.

  • Stdout and stderr log files

    hello everyone,
    I recently used Oracle SOA Suite 10g to deploy my WAR file in it, i found the log file which contains the stdout and stderr in "ORA_HOME\opmn\logs\default_group~home~default_group~1.log".
    My question is: How can I view this log file through the Application Server Control?

    Hi Hussam,
    received your screen shot and it just misses the vital pieces, the content above the blue line. On the upper right left you will find four links called Setup, Logs, Help, Logout. Logs might be greyed out and not working. To make this working click on the name of type Application Server (J2EE.wbt in your case). This will open a page for the Application Server. Logs should be a normal link now.
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Capturing Stdout and Stderr of Process before it finishes

    Dear all,
    I have to run a very long external task from java. This external program prints several messages while running. I am able to get these messages (and print them) with process.getInputStream. The problem is that I can only print those messages after the external program ends. Please, could anyone guide me on how to print those messages at the time they are printed by the external program?
    Thank you very much,
    Federico
    PS: I am implementing all these using the SwingWorker class. It works properly except for the above mentioned problem.

    I have modified my code according to the example shown below and now it works properly.
    The problem was that I was using:
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "MrBayesErr", System.err);StreamGobbler class is like the one in: http://www.velocityreviews.com/forums/t144656-runtimeexec-redirection-help-needed-mysql.html
    I do not understand why that did not work. However, with the modifications shown below now it works.
    Thank you,
    Federico
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    public class MainClass {
      public static void main(String[] args) throws Exception{
        Runtime r = Runtime.getRuntime();
        String[] nargs = { "sh", "-c", "for i in 1 2 3; do echo $i; done" };
        Process p = r.exec(nargs);
        BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = is.readLine()) != null)
          System.out.println(line);
    }

  • Redirecting stdout of third party API?

    Good Morning (or afternoon),
    I have an interesting problem with an application that I am writing.
    I am using my own classes, as well as a third party package that somebody developed, in this application.
    I have developed a GUI for ease of use and in this GUI I have a textarea component that shows all stdout messages.
    To achieve this I simply used System.setOut(PrintStream out) to redirect the output to my textarea. Now, all stdout messages display on my textarea. So far so good.
    The problem came when I used the third party package. The third party stdout still goes to the default (terminal).
    I have to use the third party package through it's main method so I am calling ThirdPartyPackage.main(thingToPass).
    Does anyone know why this occurs, or how I can get the third party classes to use the stdout that is currently in use by the calling class?
    I am very stuck and would really appreciate any help even theoretical.
    Thankyou in advance.

    I am doing exactly the same thing, here's the code that calls an external process and appends the output to a JTextArea:
    (txtOutput is the JTextArea I'm showing the output in)
              try
                   Process proc = Runtime.getRuntime().exec(progName);
                   InputStream procStdout = proc.getInputStream();
                   InputStream procStderr = proc.getErrorStream();
                   int exit = 0;
                   boolean processEnded = false;
                   while(!processEnded)
                        try
                             exit = proc.exitValue();
                             processEnded = true;
                        catch(IllegalThreadStateException e) {} // still running
                        int n = procStdout.available();
                        if(n > 0)
                             byte[] pbytes = new byte[n];
                             procStdout.read(pbytes);
                             //System.out.print(new String(pbytes));
                             //System.out.flush();
                             txtOutput.append(new String(pbytes));
                             txtOutput.setCaretPosition(txtOutput.getText().length());
                        n = procStderr.available();
                        if(n > 0)
                             byte[] pbytes = new byte[n];
                             procStderr.read(pbytes);
                             System.err.print(new String(pbytes));
                             System.err.flush();
                        try
                        Thread.sleep(10);
                        catch(InterruptedException e) {}
                   System.out.println();
                   System.out.println("Process exited with: " + exit);
              catch (java.io.IOException e)
                   System.out.println(e.toString());
              }

  • Redirecting stdOut to a JTextArea - Help!

    I want to redirect stdOut via System.setOut to a JTextArea - I'm most of the way there but I keep getting some strange errors. I'd really appreciate some help!
    I have a class called MainDebug which in its constructor calls
    System.setOut(new DebugStream((OutputStream)System.out));
    it also has a method
    public void appendMessage(String message)
    txtAreaDebug.append(message);
    where txtAreaDebug is the JTextArea to which I want to redirect stdOut.
    In MainDebug is another class called DebugStream (which is referred to in MainDebug's constructor). The entirety of that class is as follows:
    public class DebugStream extends java.io.PrintStream
    public void println(String x)
    MainDebug.this.appendMessage(x);
    public void write(int x)
    MainDebug.this.appendMessage(new Integer(x).toString());
    When I build I get these errors:
    pcgen\gui\MainDebug.java:63: cannot resolve symbol
    symbol : constructor DebugStream (java.io.OutputStream)
    location: class pcgen.gui.MainDebug.DebugStream
    System.setOut(new DebugStream((OutputStream)System.out));
    ^
    pcgen\gui\MainDebug.java:166: cannot resolve symbol
    symbol : constructor PrintStream ()
    location: class java.io.PrintStream
    public class DebugStream extends java.io.PrintStream
    For the first error, shouldn't DebugStream inherit the proper constructor from PrintStream? And I have no clue about the second error - I believe I've extended the class correctly.
    Pearls of wisdom appreciated! :)

    Constructors aren't inherited from superclasses, so you'll need to supply your own constructor for DebugStream.
    FWIW, I've done this before and here's my version of DebugStream:
       private class MyPrintStream extends PrintStream
          public MyPrintStream(OutputStream pOut)
             super(pOut);
          public void println(String pString) {
             if (mResultsPanel != null)
                mResultsPanel.append(pString);
             super.println(pString);
          public void println(Object pObject)
             if (mResultsPanel != null)
                mResultsPanel.append(pObject.toString());
             super.println(pObject);
       }where mResultsPanel has a reference to the JTextArea.
    Good luck,
    Tom

  • How do you monitor a background thread and update the GUI

    Hello,
    I have a thread which makes its output available on PipedInputStreams. I should like to have other threads monitor the input streams and update a JTextArea embedded in a JScrollPane using the append() method.
    According to the Swing tutorial, the JTextArea must be updated on the Event Dispatch Thread. When I use SwingUtilities.invokeLater () to run my monitor threads, the component is not redrawn until the thread exits, so you don't see the progression. If I add a paint () method, the output is choppy and the scrollbar doesn't appear until the thread exits.
    Ironically, if I create and start new threads instead of using invokeLater(), I get the desired result.
    What is the correct architecture to accomplish my goal without violating Swing rules?
    Thanks,
    Brad
    Code follows:
    import java.lang.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SystemCommand implements Runnable
         private String[] command;
         private PipedOutputStream pipeout;
         private PipedOutputStream pipeerr;
         public SystemCommand ( String[] cmd )
              command = cmd;
              pipeout = null;
              pipeerr = null;
         public void run ()
              exec ();
         public void exec ()
              // --- Local class to redirect the process input stream to a piped output stream
              class OutputMonitor implements Runnable
                   InputStream is;
                   PipedOutputStream pout;
                   public OutputMonitor ( InputStream i, PipedOutputStream p )
                        is = i;
                        pout = p;
                   public void run ()
                        try
                             int inputChar;
                             for ( ;; )
                                  inputChar = is.read();
                                  if ( inputChar == -1 ) { break; }
                                  if ( pout == null )
                                       System.out.write ( inputChar );
                                  else
                                       pout.write ( inputChar );
                             if ( pout != null )
                                  pout.flush ();
                                  pout.close ();
                             else
                                  System.out.flush();
                        catch ( Exception e ) { e.printStackTrace (); }     
              try
                   Runtime r = Runtime.getRuntime ();
                   Process p = r.exec ( command );
                   OutputMonitor out = new OutputMonitor ( p.getInputStream (), pipeout );
                   OutputMonitor err = new OutputMonitor ( p.getErrorStream (), pipeerr );
                   Thread t1 = new Thread ( out );
                   Thread t2 = new Thread ( err );
                   t1.start ();
                   t2.start ();
                   //p.waitFor ();
              catch ( Exception e ) { e.printStackTrace (); }
         public PipedInputStream getInputStream () throws IOException
              pipeout = new PipedOutputStream ();
              return new PipedInputStream ( pipeout );
         public PipedInputStream getErrorStream () throws IOException
              pipeerr = new PipedOutputStream ();
              return new PipedInputStream ( pipeerr );
         public void execInThread ()
              Thread t = new Thread ( this );
              t.start ();
         public static JPanel getContentPane ( JTextArea ta )
              JPanel p = new JPanel ( new BorderLayout () );
              JPanel bottom = new JPanel ( new FlowLayout () );
              JButton button = new JButton ( "Exit" );
              button.addActionListener ( new ActionListener ( )
                                       public void actionPerformed ( ActionEvent e )
                                            System.exit ( 0 );
              bottom.add ( button );
              p.add ( new JScrollPane ( ta ), BorderLayout.CENTER );
              p.add ( bottom, BorderLayout.SOUTH );
              p.setPreferredSize ( new Dimension ( 640,480 ) );
              return p;
         public static void main ( String[] argv )
              // --- Local class to run on the event dispatch thread to update the Swing GUI
              class GuiUpdate implements Runnable
                   private PipedInputStream pin;
                   private PipedInputStream perr;
                   private JTextArea outputArea;
                   GuiUpdate ( JTextArea textArea, PipedInputStream in )
                        pin = in;
                        outputArea = textArea;
                   public void run ()
                        try
                             // --- Reads whole file before displaying...takes too long
                             //outputArea.read ( new InputStreamReader ( pin ), null );
                             BufferedReader r = new BufferedReader ( new InputStreamReader ( pin ) );
                             String line;
                             for ( ;; )
                                  line = r.readLine ();
                                  if ( line == null ) { break; }
                                  outputArea.append ( line + "\n" );
                                  // outputArea.paint ( outputArea.getGraphics());
                        catch ( Exception e ) { e.printStackTrace (); }
              // --- Create and realize the GUI
              JFrame f = new JFrame ( "Output Capture" );
              f.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
              JTextArea textOutput = new JTextArea ();
              f.getContentPane().add ( getContentPane ( textOutput ) );
              f.pack();
              f.show ();
              // --- Start the command and capture the output in the scrollable text area
              try
                   // --- Create the command and setup the pipes
                   SystemCommand s = new SystemCommand ( argv );
                   PipedInputStream stdout_pipe = s.getInputStream ();
                   PipedInputStream stderr_pipe = s.getErrorStream ();
                   // --- Launch
                   s.execInThread ( );
                   //s.exec ();
                   // --- Watch the results
                   SwingUtilities.invokeLater ( new GuiUpdate ( textOutput, stdout_pipe ) );
                   SwingUtilities.invokeLater ( new GuiUpdate ( textOutput, stderr_pipe ) );
                   //Thread t1 = new Thread ( new GuiUpdate ( textOutput, stdout_pipe ) );
                   //Thread t2 = new Thread ( new GuiUpdate ( textOutput, stderr_pipe ) );
                   //t1.start ();
                   //t2.start ();
              catch ( Exception e ) { e.printStackTrace (); }
              

    Thanks for pointing out the SwingWorker class. I didn't use it directly, but the documentation gave me some ideas that helped.
    Instead of using invokeLater on the long-running pipe-reader object, I run it on a normal thread and let it consume the output from the background thread that is running the system command. Inside the reader thread I create a tiny Runnable object for each line that is read from the pipe, and queue that object with invokeLater (), then yield() the reader thread.
    Seems like a lot of runnable objects, but it works ok.

  • Redirecting stdout in 64 bit mode

    Hi,
    I have a problem. I wanted to redirect stdout to a text file and back. In 32 bit mode everything works fine using file member to struct FILE, but in 64 bit mode only data member FILE has long _pad[16]. Can anyone tell me how to use this to redirect stdout to file and visevesra. Thanks in advance.
    Amandeep

    By default in 10.6.8 it should be in 64 bit mode but to check and change it in Finder highlight Aperture, the application, and go command I to open the info window and look about 1/4 of the way down
    (Note this is from Lion so it is slightly different then what you will see)

  • Rotate Log Files - stdout.log & stderr.log

    Hi Folks,
    Whats the best way to rotate stdout.log & stderr.log.
    I am assuming that rolling of these files can not be configured using felix (please correct me if I am mistaken)
    Please advice!
    Thanks,
    Adnan

    Hi Adnan,
    There is currently no way to rotate stdout.log and stderr.log. Therefore, if you want to preserve the stdout.log and stderr.log so that they do not get truncated after restart, add the following commands before any other command in the start script.
    # Move stdout.log and stderr.log
    mv ../logs/stdout.log ../logs/stdout_$(date +%Y-%m-%d-%H%M).log
    mv ../logs/stderr.log ../logs/stderr_$(date +%Y-%m-%d-%H%M).log
    Another possible way is to disable the stdout.log and stderr.log entirely and instead output the information to the startup.log. Then you can rotate the startup.log instead.
    a) To disable the stderr.log and stdout.log, i guess you can add these lines to your crx-quickstart/server/start script:
    QUICKSTART_OPTS='-verbose -nobrowser'
    export QUICKSTART_OPTS
    b) To configure the path of the startup.log, you can add this to the start script as well (replace /path/to/startup.log with the path you would like the log to be written to instead):
    CQ_LOG=/path/to/startup.log
    export CQ_LOG
    c) Then after doing this, there is a side effect that crx output will go to the startup.log as well. to fix this, do the following:
        1) Go to crx-quickstart/server/runtime/0/_crx/log4j.xml
        2) Comment out this element <appender-ref ref="console" /> from log4j.xml
    <root>
    <level value="info" />
    <!-- appender-ref ref="console" /-->
    <appender-ref ref="error" />
    </root>
    d) Also, now you would like to rotate the startup.log file:
    "The file startup.log logs messages while the Servlet Engine starts. It is usually small, and you cannot configure it."
    The startup log cannot be rotated with CQSE facilities. Please note that logs under /server is rotated at operating system level,
    for more info see http://httpd.apache.org/docs/2.0/programs/rotatelogs.html
    Unix workaround :
    in serverctl script, replace the line :
    exec $jvmExe >> "$CQ_LOG" 2>&1
    by : 
    exec $jvmExe | /usr/sbin/rotatelogs "$CQ_LOG.%Y%m%d" 86400 >> /dev/null 2>&1
    If this doesn't seem to work, then try
    exec $jvmExe 2>&1 | /usr/sbin/rotatelogs "$CQ_LOG.%Y%m%d" 86400
    Unfortunately, I did not found any workaround for windows system.
    Hope this helps.
    Thanks,
    Varun

  • Adding redirect path and  pattern in Lion server for configuring software update server

    Adding redirect path and  pattern in Lion server for configuring software update server.Any changes

    Ok, after days of browsing on the forum I found the following hint on another discussion related to AFP access:
    "This may be a service ACL issue.
    It turns out one of the latest Apple updates turned on Service ACL's which caused AFP connections to be  blocked. Once I fixed the Service ACL in Server Admin... all connections and Single Sign On worked."
    Well, after allowing access to all services to all users with Server Admin, we were finally able to log in the server with our admin account...
    So, there must have been an update that turned on ACL's which caused even our local access, probably for OD/Kerberos, on the server to be restricted.

  • Java Swing/AWT and FX is so old school! Give me HTML and CSS for GUI!

    Dear Java,
    I am a seasoned programmer and I feel it's time JAVA implements a GUI system where it uses HTML and CSS for the GUI. For the love of god just look at the interfaces you can make using HTML and CSS alone. I am a big fan of Java Swing and the recent GUI designer for FX is quite cool. But they are just not as simple as HTML and CSS. And JavaFX has some interesting requirements for the graphics.
    I know it is possible to use JavaFX and implement the WebView/WebDriver and make it load a HTML page, etc... but why go through all the trouble?
    Just imagine... if you make Java where it has powerful back-end to do what it does best and the HTML/CSS powered GUI on the front-end. It will make the lives of many developers much much easier.
    I am not sure whether a Swing designed GUI will be faster than a HTML designed GUI... but if you look at a traditional browser and how fast it renders HTML/CSS, I am sure if Java had a native Form where it uses HTML and CSS to render the GUI, Java will make the dreams of many programmers a reality.
    Make it happen!!!!

    Check this i solve problem just now using this
    https://wiki.archlinux.org/index.php/Ja … ow_Manager

  • How to create database and table with GUI?

    How to create database and table with GUI?
    for linux can do that?
    or have only way to create table by use sql*plus.
    everyone please help me.
    thanks

    go to www.orasoft.org
    here is a gui tool.
    null

  • What does too many http redirects mean and how do I fix it

    Does anyone know what the **** "Too many http redirects" means, and how the **** do I fix it ??

    500 errors in the HTTP cycle
    Any client (e.g. your Web browser or our CheckUpDown robot) goes through the following cycle when it communicates with the Web server:
    Obtain an IP address from the IP name of the site (the site URL without the leading 'http://'). This lookup (conversion of IP name to IP address) is provided by domain name servers (DNSs).
    Open an IP socket connection to that IP address.
    Write an HTTP data stream through that socket.
    Receive an HTTP data stream back from the Web server in response. This data stream contains status codes whose values are determined by the HTTP protocol. Parse this data stream for status codes and other useful information.
    This error occurs in the final step above when the client receives an HTTP status code that it recognises as '500'. Frank Vipond. September 2010.
    Fixing 500 errors - general
    This error can only be resolved by fixes to the Web server software. It is not a client-side problem. It is up to the operators of the Web server site to locate and analyse the logs which should give further information about the error.
    Fixing 500 errors - CheckUpDown
    Please contact us (email preferred) whenever you encounter 500 errors on your CheckUpDown account. We then have to liaise with your ISP and the vendor of the Web server software so they can trace the exact reason for the error. Correcting the error may require recoding program logic for the Web server software, which could take some time.
    http://www.checkupdown.com/status/E500.html

Maybe you are looking for

  • How to get pictures from iphone 4s to iphoto?

    I am unable to get the pictures from my new iPhone 4s transfered to iPhoto on my iMac (version 10.5.8). It does sync via iCloud to my iPad, but it will not transfer pictures to iPhoto when connecting the phone to my iMac. The phone doesn't appear on

  • Hard Drive transplant woes

    I bought a 2011 Macbook Pro and put my old HD (from a 2008 macbook) in and booted it - successfully. The problem is that Logic and some other software are demanding license information again. Why? Shouldn't everything just work as before?

  • Looking for Documentation on PeopleSoft Delivered App Packages.

    Hey Guys, Do anyone know whether PeopleSoft provide documentation for the Delivered App Packages. I'm expecting something like Java documentation, we get complete documentation like complete list of classes, respective methods, properties, and relati

  • Intercompany STO with inbound delivery with freight....Urgent

    Hi, I have following scenario to map. There are 2 company codes A & B and a shipment of goods is to be transferred from A to B. I wish to use Intercompany STO process with UB. However, A & B are geographycally separated so there involves transportati

  • Installing Veritas on Solaris 9

    Hi, I am new to solaris and am having a few problems installing veritas Netbackup 5 on Solaris 9. The CD mounts fine but when I type in ./install to start the installation I get an error message saying: install: not found Any help would be appreciate