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 Patel

You 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);
}

Similar Messages

  • Linux server(how to save command out put to another file. )

    hi all,
    i have Q ?
    how to save command out put to another file.
    Ex: #ps -ef
    that particular cmd output i need to save another file.
    is it possible ...if possible ..please let me know
    And how to save command history in Linux.

    df -h >> /oracle/output.log
    /oracle -- mount point name
    Regards
    Asif Kabir

  • 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();
    }

  • How to avoid time out error in abap program

    How to avoid time out error in abap program
    based on performance wise i want please help

    Timeout occurs when a statement exceeds its time limit.To avoid this we need to tune the statements.
    I can give give you few tips for tune a select stament.
    1.The order of the feilds in the select statement should be same as the order of fields in the database table.
    2.It is always advisible to use the key fields when you are using the where clause.
    3. Sort the internal table while using the for all entreis statements.
    4.Use index in where clause if necessary.
    5.When you have a read statement user binary search but before this a sort statement should be there.
    6. Check your program with the Tcode ST05 and check which statement takes much time based on that tune that.

  • 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.

  • Invoking Java from C and capturing System.out

    Hi,
    I know very little about C but have a question related to invoking a Java process from C. Perhaps someone can help me.
    I've been looking at the example at http://java.sun.com/docs/books/jni/html/invoke.html and seen how to invoke my Java program with:
    (*env)->CallStaticVoidMethod(env, cls, mid, args);
    in their example the Java program prints one line to System out with:
    System.out.println("Hello World " + args[0]);
    and says running the program produces:
    Hello World from C!
    What I want to know is, how in the C program can I capture the output the Java program sends to System.out, as I want to do something with the output other than have it print into the console.
    Hope that makes sense.

    I'm not totally clear on your question but I'll take a stab.
    It seems to me like you are trying to get the output from a java program into a C program. If this is the case then there are many ways to do this - many of which are more simple that using JNI. However, if you absolutely must use JNI for this application then I suggest you take some more time to learn about C and JNI as I imagine this sort of thing is non-trivial and will required a level of understanding of C that you currently don't have. You may also want to cross-post onto the JNI forum.
    If you can do this without using JNI then I'd suggest doing the standard fork/exec/pipe routine. This means, that in your C program you will call the functions fork (to create a new process that is subordinate to the currently running one), exec (in the subprocess which will replace the current program image in memory with that of another program you wish to execute, in this case, a JVM with a running application), and popen (which creates a "pipe" between the standard output of the Java program [System.out] and some input stream in the C program).
    Finding an example of a program that does this fork/exec/pipe pattern on the web shouldn't be too hard. Hope this helps.
    -mike

  • How to capture System Error in XI?

    Hello All,
    1. Can any one tell me , How to capture the system error , Adapter Error and send the alert to make sure the guarenteed delivery from Source to Target via XI ?
    2.I have done the configuration for to capture the mapping error in transaction ALRTCATDEF .But still i am not able to see any messages in my Alert Inbox???
    I have checked with the two weblogs Alert step by step and Alert Trouble shooting guide.but still i am not getting any messages in Alert inbox .Any one can tell me how to fix this?
    Thanks!

    Hi,
      You wrote:
    <i>How to capture the system error , Adapter Error </i>
    Errors are captures in many ways and at different stages,
    like alert, sld errors or even sxmb_moni or even with visual administrator trace, I am not sure of your requirement but if you want a centrlished point to access all these error you may refer a good example as,
    /people/michal.krawczyk2/blog/2005/09/07/xi-why-dont-start-searching-for-all-errors-from-one-place
    <i>have checked with the two weblogs Alert step by step and Alert Trouble shooting guide.but still i am not getting any messages in Alert inbox .Any one can tell me how to fix this?</i>
    The two weblogs are my favourite and best resources but still if you are missing, please elaborate if you are getting any errors or other fesible traces as to why your alerts are not coming in inbox.
    Regards,
    Anirban.

  • How to view System.out.print() messages for adapters in OIM 9.0.3

    I have created an adaptor for OIM from a java jar file. When that adaptor executes after some updates on tables it produces some execptions/error.
    I can not see the details of these exceptions as I do not know where is the standard output located when adapter is executed via OIM.
    Where cen I see output from my code lines that contain: System.out.println()?
    thanks

    I am not sure if logging is enabled as OIM was installed previously by another person - how can I check if it is enabled and how to use log4j in this case?
    OIM Design Console window shows no messages comming from my System.out.print() statements.
    /br
    Djeno

  • How to replace System.out.println() using templates

    can you give the complete code for my problem which is given below.
    package include;
    public class P
    public static cout(int a)
    System.out.println( a);
    public static cout(int a,int b)
    System.out.println(a + b);
    // like this i need to write to accept parameters from the class. which is importing this package
    for some more examples
    public static cout(int a,String s)
    System.out.printn(a +s);
    and many more type i.e. all types of arrangements of datatypes
    the above is the package called "include" Now Iam Importing the package in the class Hello:
    import include.P;
    public class Hello
    public static void main(String args[])
    int i=10;
    float f=12.23;
    String s="hello";
    P.cout(i,f); //cout is the static method of package(include) class " P"
    P.cout("welcome",s)
    // like this I want to send any type and any no of arguments as the System.out.println()
    will handle.
    My aim is to replace the System.out.println() with P.cout() which can be achieve in my idea by calling the static method ( such as cout() ) which internally use System.out.println() method. I am facing problem in achieving this because we donot know which type and how many parameters he will send .
    My task is we have to create a method which will accept any no.of arguments and is of any type.I think this can be done BY USING TEMPLATES.
    So please understand my problem and send me reply.I am waiting for your reply.
    thank you.

    Although I am not sure why you are doing this, if you really are trying to code a replacement for System.out.println then:
    out is a PrintStream and the println methods of PrintStream have the following signatures:
    void println()
    Terminate the current line by writing the line separator string.
    void println(boolean x)
    Print a boolean and then terminate the line.
    void println(char x)
    Print a character and then terminate the line.
    void println(char[] x)
    Print an array of characters and then terminate the line.
    void println(double x)
    Print a double and then terminate the line.
    void println(float x)
    Print a float and then terminate the line.
    void println(int x)
    Print an integer and then terminate the line.
    void println(long x)
    Print a long and then terminate the line.
    void println(Object x)
    Print an Object and then terminate the line.
    void println(String x)
    Print a String and then terminate
    So you should only need to create corresponding methods.

  • Tomcat Java Servlets, how to log System.out.println() messages

    I have recently installed a new (x86) Mac OS Xserve, and am porting some Java application Servlets from an existing older Mac OSX server. All the servlets were working (I am connecting via port 9006). I have carefully used the old JDK 1.4 compiler, edited my server.xml (for port 9006) and web.xml files, etc. The Tomcat example servlets work fine, and all my (other) servlets work fine, with one exception, where I get the typically vague "java.io.IOException: Server returned HTTP response code: 500" message.
    Trouble is, I cannot get the Java System.out.prinln statements to go to the Tomcat/logs/ log files (they are all there and updating with Tomcat HttpServlet messages), in order to properly debug.
    Is there a server.xml value somewhere I can make the change?
    On another minor (possibly related) point, does anyone know what the path info ='null' means in the Tomcat access log? e.g.,
    StandardContext[/my_servlets]: Mapped to servlet 'myServlet' with servlet path '/myServlet' and path info 'null'
    It is the only other suspicious message I get in all the logs.
    One other point: my java application that fails uses threads. All the individual classes that use the threads work when run interactively, but as soon as I call them from final Serlet class that extends HttpServlet, I get a null pointer exception. Is there something unique about the Tomcat 4.1 threading that could be causing it?
    I want to avoid upgrading to Tomcat 5 at this point, if I can avoid it. My applications are modest in scope, and the last time I upgraded to Tomcat 5, it took me days to get it working properly, and I lost all access to it from the Server Admin application.

    I have found a solution: Via the Tomcat Admin web page I set the Context field "Swallow Output" to "true".

  • How to get System.out msg displayed in logs

    Running SJSWSEE6.1 SP5 on Solaris
    How do I get the System.out.println messages to display in the Web Server 6.1 error/access log??
    Thanks..

    Hi,
    In your server.xml, check that the properties 'logstderr' and 'logstdout' are set to 'true'. The messages will then appear in the errors log file.
    <LOG file="<path to errors file>" loglevel="info" logtoconsole="true"
    usesyslog="false" createconsole="false" logstderr="true" logstdout="true" logvsid="false"/>
    Also, see docs at http://docs.sun.com/source/817-6248/crsrvrx.html
    Hope this helps.

  • Hibernate how to  disable system.outs.....

    Hi
    I am using hibernate to conect to mySQL database, but I am getting a bunch of system.outs that slow down the process.
    is there anyyway tor emove this system outs form there
    I am suing netbeans and javax.persistence
    example:
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(19157736)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(29310343)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(30472956)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(17680053)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(12122347)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(31332340)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(5218268)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(25699763)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.156--ServerSession(1760304)--Connection(33539718)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    thanks !!

    First, read the documentation of Toplink how to configure their logger.
    Second, it look like that you're creating a new session everytime on every query? That is very expensive. Your code logic might need a review.

  • How to capture Wnidows(OS) event from Java program

    Hi,
    I am developing one application , in that if the user didn't do any thing in 15 mins,i need to log out from my application(not windows).Here i need to check Java event as weel as windows(OS) events also.Any one knows how to capture the OS events??

    I want to know the status of mouse and keyboard(Windows 2000).If the status of the mosue or keyboard doesn't change from 15min i need to log of the java application.

  • How to capture Document Numbers when executing rfbibl00 program in 'C' mode

    Hi
    I am using rfbibl00 program to post documents(FB01 transaction). I have used call transaction option by selecting callmode = 'C' .
    As per our requirement the document numbers should get displayed in the report after the postings happened.
    Can any one tell me how to capture the document numbers.
    Thanks & Regards
    Madhu

    Hi,
    1) with:
      GET PARAMETER ID 'BLN' FIELD BL01-BELNR.
      GET PARAMETER ID 'BUK' FIELD BL01-BUKRS.
      GET PARAMETER ID 'GJR' FIELD BL01-GJAHR.
    But you must acquiring an item that clerk used FB01 only 1 times
    2) use call transaction 'FB01' ... messages into messtab
    and analyse messtab
    A.

  • How to call an alv report from another program and return back

         Hello ,
    I am calling one abap program (Prgm B) from another program (Prgrm A).
    Here, Prgm B is an ALV report. I have fetch some data from Prgem B that gets stored in an internal table.
    Now, I am using below code in Prgrm A,
      SUBMIT Prgrm B VIA SELECTION-SCREEN
                          WITH SELECTION-TABLE rspar
                          EXPORTING LIST TO MEMORY
                          AND RETURN.
    When Prgrm A executed, it lead me to selection screen of Prgrm B and when I click F8, it shows me the report output, In short, it doesnt return back to Prgrm A. It ends up showing me the alv report if Prgrm B even afetr using RETURN statement.
    I want to get back to Prgrm A by fetching some data from Prgrm B.
    Please let me know, if i am missing something.
    Regards,
    Seema

    Hi Seema,
    Refer below code.
    DATA: v_matnr LIKE mara-matnr.
    DATA: t_listobject TYPE abaplist OCCURS 0 WITH HEADER LINE.
    DATA: t_mara TYPE mara OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF t_ascilist OCCURS 0,
             line(200).
    DATA: END OF t_ascilist.
    data var(3) type c.
    SELECT-OPTIONS: s_matnr FOR v_matnr.
    var = '  3'.
    START-OF-SELECTION.
       SUBMIT ztestaks1 WITH s_matnr IN s_matnr EXPORTING LIST TO MEMORY
       AND RETURN.
       CALL FUNCTION 'LIST_FROM_MEMORY'
            TABLES
                 listobject = t_listobject
            EXCEPTIONS
                 not_found  = 1
                 OTHERS     = 2.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ELSE.
         CALL FUNCTION 'LIST_TO_ASCI'
    *     EXPORTING
    *       LIST_INDEX               = -1
    *       WITH_LINE_BREAK          = ' '
           TABLES
             listasci                 = t_ascilist
             listobject               = t_listobject
           EXCEPTIONS
             empty_list               = 1
             list_index_invalid       = 2
             OTHERS                   = 3.
         IF sy-subrc <> 0.
           MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
         ELSE.
           WRITE:/ 'Below are the lines from the submitted program.'.
           LOOP AT t_ascilist.
             WRITE:/ t_ascilist-line.
           ENDLOOP.
           SKIP 2.
         ENDIF.
       ENDIF.
       IMPORT t_mara FROM MEMORY ID 'T_MARA'.
       WRITE:/
    'Here is the output from the table exported from the submitted program.'
       LOOP AT t_mara.
         WRITE:/ t_mara-matnr.
       ENDLOOP.
    Submitted program
    REPORT  ZTESTAKS1.
    DATA: v_matnr LIKE mara-matnr,
           v_maktx LIKE makt-maktx.
    DATA: t_mara TYPE mara OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF t_makt OCCURS 0,
             matnr LIKE makt-matnr.
    DATA: END OF t_makt.
    SELECT-OPTIONS: s_matnr FOR v_matnr,
                     s_maktx FOR v_maktx.
    START-OF-SELECTION.
       SELECT matnr INTO TABLE t_makt
                    FROM makt
                   WHERE matnr IN s_matnr
                     AND maktx IN s_maktx.
    if not t_makt[] is initial.
       SELECT * FROM mara
                INTO TABLE t_mara FOR ALL ENTRIES IN t_makt
               WHERE matnr = t_makt-matnr.
    endif.
       EXPORT t_mara TO MEMORY ID 'T_MARA'.
       WRITE:/ 'This list is from the submitted program'.
       SKIP 1.
       LOOP AT t_mara.
         WRITE:/ t_mara-mtart.
       ENDLOOP.
    Hopes this helps you.
    Thanks,
    Ashok.

Maybe you are looking for

  • Plz help me with the workflow.........

    I'm trying my level best to mould my expectations according to the software but till now no success,can you plz explain to make the timeline less cluttered and organized we make secondary storylines and compound clips since you can't keep too many th

  • Business area not appearing in GR of Subcontracting (Movement type 543)

    Dear Gurus We have created new plant B  (and assigend to Company code B) by copying existing plant A (assigned to Company code A).  Business area B was defined and assigned to plant B and valuation area. When we do normal GR document business area ap

  • Problem with Z70-80 BIOS ABCN80WW

      Salve ho appena aggiornato il mio Lenovo Z70-80 passando dalla versione firmware ABCN32WW a ABCN80WW. Aggiornamento riuscito correttamente. Al riavvio non funzionano piu le due porte usb2.0 nello specifico non sono piu alimentate da quando si è car

  • How to select local printer while printing

    Dear All We have developed ERP solution in oracle 10g forms & reports. and deployed on web using oracle apllication server 10g. I need help when we are giving print from oracle forms directly it goes to server default printer. instead we want to sele

  • Not able to use FTPS

    Hi All, I tried to enable the implicit FTPS in CDB and followed the Admin guide. However, not able to connect to it using any of the FTPS clients. Getting an error: could not connect to the server. How to check whether the steps performed for FTPS en