Redirect standart output to file

i want to ask how to redirect standart output to file,
if i have statement like this System.out.println("hello"); i want hello not print in console but print to file
thx

Here is sample code for that:
  static{
    try {
      PrintStream obj_ps = new PrintStream(new FileOutputStream("internal.log"));
      System.setOut(obj_ps);
      System.setErr(obj_ps);
    catch (FileNotFoundException ex) {
      JOptionPane.showMessageDialog(null, "Error creating log file", "Error", JOptionPane.ERROR_MESSAGE);
  }

Similar Messages

  • Redirecting standart output to a String

    Is there any way to redirecting System.out so that it goes to a string instead of the
    console?

    I am sorry but I am totally unable to understand your question. However if I am anywhere close to what you are asking you just store the value in an instantiated String.
    e.g.
    instead of doing
    System.out.println("hello world");
    String output = "hello world";and then you could append to it
    output.concat("hi there");

  • Redirect output to file?

    Hi there,
    is it possible to redirect the output of a canvas3d to file (jpg or so)?
    greetz, ToM

    Use this as a starting point: http://forums.java.net/jive/thread.jspa?forumID=70&threadID=13134&messageID=101107#101107
    Mike

  • How to redirect CELLCLI output to text file

    Hi,
    I would like to redicrect the output of the cellcli command to a text file .
    For example , how to redirect the output of this command to a text file on /tmp
    CellCLI> list metrichistory where objectType = 'CELL' -
    and name = 'CL_TEMP'Thanks

    cellcli has spooling capabilities similar to sqlplus:
    CellCLI> help spool
      Usage:  SPO[OL] [<filename> [ CRE[ATE] | REP[LACE] | APP[END]] | OFF ]
      Purpose: SPOOL <filename>: Direct the results to the file <filename>.
               SPOOL OFF: Turn off the spooling.
               SPOOL: Check the current spooling status.
      Arguments:
        <filename>: The filename where the results will be output.
      Options:
        [APPEND]: If the filename already exists, the following output will
                  be appended to the file. Without this option, the existing file
                  contents will be replaced.
        [CREATE]: If the filename already exists, an error is reported.
        [REPLACE]: If the filename already exists, the contents will be
                  replaced.  This is the default, when no option is provided.
      Examples:
        spool myfile
        spool myfile append
        spool off
        spoolBut if you are trying to script it, it would be easier to just run it command line:
    # cellcli -e "list metrichistory where objectType = 'CELL' and name = 'CL_TEMP'" > /tmp/CL_TEMP.txtAlso look into dcli which allows you to run cellcli commands on one or more cells from a compute node.
    Good luck.

  • Redirecting XSLT output to multiple files

    Hi,
    I am trying to redirect the output of the XSLT into multiple files using
    <xsl:variable name="filename" select="concat(@id,'.xml')" />
    <redirect:write select="$filename">
    </redirect:write>I dont want to hard-code the directory of the $filename in XSL, I want to set it or resolve it programatically in the java code.
    Can you please tell me if this can be done in someway ?

    Aravinda wrote:
    I dont want to hard-code the directory of the $filename in XSL, I want to set it or resolve it programatically in the java code.
    Can you please tell me if this can be done in someway ?You + setParameter + method of your Transformer in java code to set parameters. like below:
    transformer.setParameter("message1", "This is my message to XSLT from Java Class.");
    transformer.setParameter("message2", "Hello XSLT how are you?");
    . . .You can retrieve above parameters in global parameters/variables(must be as child of xsl:stylesheet element in xslt) defined in xslt like below:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:param name="message1"></xsl:param>
         <xsl:variable name="message2"></xsl:variable>
         <xsl:template match="/">
              <xsl:value-of select="$message1"/>     // retrieving message1
              <xsl:value-of select="$message2"/>     // retrieving message2
              <xsl:value-of select="concat($message1,$message2)"/>     // performing concat on message1 and message2
         </xsl:template>
    </xsl:stylesheet>*Cheers
    TYPUROHIT*
    (Tejas Purohit)

  • Redirect the output of SQL*Plus to the file

    Hi all,
    I have the following command to run:
    sqlplus username/password @myfile.sql
    I don't know how to redirect the output to the file.
    Also in the script myfile.sql I have the defined variable, &VP and
    How can I substitute this variable(&VP) at the run time.
    Thanks,
    JP

    Assumed you like to replace your defined variable VP by number 4. SInce it is posintional parameter,instead of wrinting &VP, write
    VP:=&1
    sqlplus>spool redirect.txt
    sqlplus>@myfile.sql 4
    sqlplus>spool off

  • Redirect SM50 output on unix file

    Hello,
    how can we execute daily SM50 daily and redirect html output on unix file?
    I Tried SE38, execute SM50 succefully, but no way to redirect output of this transaction on a unix file ?
    Thanks in advance.

    Hi majda,
    Hope you are doing good.
    Maybe check /nSM49 and create a OS command using ">>" operator Divyanshu mentioned:
    Restrict Authorizations for Executing External Commands - SAP NetWeaver Application Server ABAP Security Guide - SAP Lib…
    Thank you!
    Kind Regards,
    Hemanth
    SAP AGS

  • Invoking a call to a window executable fails when request output to file

    Hi,
    When invoking a call to a window executable it fails(returns 1 instead of 0) when requesting output to file by using "> filename.txt". This nornally works when run directly within a
    windows command prompt, and it also works if I don't add the "> filename.txt" at the end. Also instead of outputting to a file I would like the same called executable to output to a memory variable that I can extract data without going to a external text file.
    Below is the .java file
    package com.insequence.gv;
    public class Jinvoker {
              public static int invoke(String program) throws java.io.IOException, java.lang.InterruptedException
                   System.out.println("invoking program: " + program);
                   Process p = Runtime.getRuntime().exec(program);
                   int exitValue = p.waitFor();
                   return exitValue;
              public static void main(String[] argv)
                   try
                   System.out.println("invoker start");
    //               int retval = invoke("c:\\tvalesky\\java\\invoker\\targetexe arg1 arg2 arg3");
    //               int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalinfo.exe C:\\data\\EarthData2005\\Ortho\\no_collaged.tif");
                   String arg1 = "C:\\data\\EarthData2005\\Ortho\\no_collaged.tif > c:\\testing.txt";
    //               String arg1 = "C:\\data\\EarthData2005\\Ortho\\no_collaged.tif";
                   int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalinfo.exe " + arg1);
    //               int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalinfo.exe");
    //               String arg1 = "-s_srs epsg:26915 -t_srs epsg:4326 C:\\data\\EarthData2005\\Ortho\\no_collaged.tif C:\\data\\EarthData2005\\Ortho\\no_collaged2.tif";
    //               int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalwarp.exe " + arg1);
    //               int retval = invoke("C:\\testing.bat C:\\data\\EarthData2005\\Ortho\\no_collaged2.tif");
                   System.out.println("invoker end: returned " + retval);
                   catch(java.io.IOException e)
                        System.out.println("IOException caught: " + e);
                   catch(java.lang.InterruptedException e)
                        System.out.println("InterruptedException caught: " + e);
    Thanks,
    John Mitchell

    Well, if you ultimately want the output from the process, you don't need to redirect it to a file first. Just read from the standard output of the process. See [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html#getInputStream()]Process.getInputStream and Process.getErrorStream. You'll need to read from both simultaneously so you'll need to create two threads. You could also use [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html]ProcessBuilder if you're using Java 1.5

  • XSQL output to file

    Hi, i've a simple xsql file like that:
    <?xml version="1.0"?>
    <xsql:query connection="demo" mlns:xsql="urn:oracle-xsql">
    SELECT *
    FROM Aircraft
    </xsql:query>
    and i would like to redirect the output of the query in a XML file (like name.xml).
    Please helm me.
    Thank you.
    Andrea

    A XSQL query may be developed in JDeveloper.
    http://www.oracle.com/technology/pub/articles/vohra_xsql.html

  • Redirecting cmd output to a JTextArea

    can anyone help me, im curious how can the compilers for java e.g.: Netbeans, JCreator, redirect the command promt output to a JTextArea..
    can anyone guide me on what class to look at??
    thanks a lot

    here is a simple class that redirects the standard output to a file called a.txt. you have to look into the class java.class.System. and other i/o classes
    import java.io.PrintStream;
    public class A {
        public A() {
        public static void main(String[] args) throws Exception {
            PrintStream fileOut = new PrintStream("a.txt");
            System.setOut(fileOut);
            for (int i = 0; i < 10; i++) {
                System.out.println(i);
    }for your case where output goes to a textArea you might wanna use a multithreaded solution. redirect your output to a file as above and use the thread to read the file and paste text into your text area. there is other better solution that directly passes data into the textArea. i'll post it if can find it in my code base.

  • How to write output to file in flash

    hi all experts.
    I want to monitor a specific link. Lets say when it goes down, i want to write the following to a file in flash called link_mon.txt
    link down <show clock output>
    When it gets back up
    link up <show clock output>
    I know how to write the applets and use sla tracking for monitoring, i just want to know how to write the output(user defined) to a file in flash ?

    What you want to do is not possible using applets.  You can write CLI output to flash using the redirect command:
    action 1.0 cli command "enable"
    action 2.0 cli command "show clock | redirect flash:/output.txt"
    But you cannot include your own custom text.  For that, you will need to use an EEM Tcl policy.  Within the Tcl policy, the code to write the output to flash would look like:
    if { [catch {cli_open} result] } {   error $result $errorInfo}array set cli $resultset fd [open "flash:/output.txt" "a"]set output [cli_exec $cli(fd) "show clock"]puts $fd "link down $output"close $fd

  • IS IT POSSIBLE TO REDIRECT THE OUTPUT TO ANOTHER PAGE?

    Hi all,
    Is it possible to redirect the output when I excute my query in iSQL*plus to another predifined html page?
    If yes how do I do this?
    Thanks a mill

    You could do this..just read on..
    It would generate a html page for you...and..so on..!
    In addition to plain text output, the SQL*Plus command-line interface enables you to generate either a complete web page, or HTML output which can be embedded in a web page. You can use SQLPLUS -MARKUP "HTML ON" or SET MARKUP HTML ON SPOOL ON to produce complete HTML pages automatically encapsulated with <HTML> and <BODY> tags.
    By default, data retrieved with MARKUP HTML ON is output in HTML, though you can optionally direct output to the HTML <PRE> tag so that it displays in a web browser exactly as it appears in SQL*Plus. See the SQLPLUS MARKUP Options and the SET MARKUP command for more information about these commands.
    SQLPLUS -MARKUP "HTML ON" is useful when embedding SQL*Plus in program scripts. On starting, it outputs the HTML and BODY tags before executing any commands. All subsequent output is in HTML until SQL*Plus terminates.
    The -SILENT and -RESTRICT command-line options may be effectively used with -MARKUP to suppress the display of SQL*Plus prompt and banner information, and to restrict the use of some commands.
    SET MARKUP HTML ON SPOOL ON generates an HTML page for each subsequently spooled file. The HTML tags in a spool file are closed when SPOOL OFF is executed or SQL*Plus exits.
    You can use SET MARKUP HTML ON SPOOL OFF to generate HTML output suitable for embedding in an existing web page. HTML output generated this way has no <HTML> or <BODY> tags.

  • Possible to redirect JSP output?

    Is it possible to redirect the output of a JSP either directly to a printer or directly to a File object? I would like to write a report template using JSP and be able to display it via a browser (so far so good, that's what JSP does) but I'd also like to take the same output that the JSP generates and either print it directly (as in printing many many reports without having to run each one in a browser and click the browser print button) AND to be able to email the report to a client.
    Each of these means I need to redirect the output of a JSP. I couldn't find anything in this forum about that. Is this even possible?
    Thank you in advance for your answers.

    The problem with using a new URLConnection is that the current session is not applied to the JSP page as desired.
    For those using Tomcat 4, which implements the Servlet 2.3 spec, this page describes how to replace the output stream of a servlet with your own.
    http://www-106.ibm.com/developerworks/java/library/j-tomcat/
    The example implements a character replacement mechanism. Using a filter and a wrapper. I modified this example to redirect the output stream to a file, which allowed me to then e-mail the output of a JSP. I did this by only using the wrapper classes.
    Here are the relavant excerpts from my code
    //Inside the servlet:
    //{snip}...
    String sFileName = "e:\\temp\\email\\temp.html";
    RedirectTextWrapper rTW =
    new RedirectTextWrapper(response, sFileName);
    gotoPage(sAddress, request, rTW);
    //{snip}...
    //Supporting classes:
    class RedirectTextStream
    extends ServletOutputStream {
    private OutputStream intStream;
    private boolean closed = false;
    public RedirectTextStream(String sFileName) {
    try{
    intStream = new FileOutputStream(sFileName);
    }catch(FileNotFoundException e){
    e.printStackTrace();
    public void write(int i)
    throws java.io.IOException {
    intStream.write(i);
    public void close()
    throws java.io.IOException {
    if (!closed) {
    intStream.close();
    closed = true;
    public void flush() throws java.io.IOException {
    intStream.flush();
    class RedirectTextWrapper
    extends HttpServletResponseWrapper {
    private PrintWriter tpWriter;
    private RedirectTextStream tpStream;
    public RedirectTextWrapper(ServletResponse inResp,
    String sFileName)
    throws java.io.IOException {
    super((HttpServletResponse) inResp);
    tpStream = new RedirectTextStream(sFileName);
    tpWriter = new PrintWriter(tpStream);
    public ServletOutputStream getOutputStream()
    throws java.io.IOException {
    return tpStream;
    public PrintWriter getWriter()
    throws java.io.IOException {
    return tpWriter;
    }

  • Redirecting the output

    Hi Satya, Thanks for helping me out couple of times earlier. I am having one more problem.
    I am able to get the runtime values of the server, but while I am unable to redirect the output to a dat file in the local box, from which I am extracting the results. I tried to use redirect(), but not able to make it work. I need help with the right command and any suggestions, that I can use to output the results to a dat file.
    Thanks again.

    Not sure I understand what you are trying to achieve. When you use redirect('./foo.dat') wlst will write the output that comes out of WLST to foo.dat. You should be able to read this file and get the outout and parse it.
    I am not sure what you are trying to do, can you post any errors you are seeing?
    -satya
    BEA Blog: http://dev2dev.bea.com/blog/sghattu/

  • Redirecting Tomcat output

    I am using Tomcat 5.0.28.
    My code uses the System.out.println( ) statements.
    However the output is redirected to the stdout file in Logs folder in Tomcat installation directory.
    I intend to see the output on the console.How can I redirect the outtput to the console and not to the stdout file?
    Any suggestion would be appreciated.

    File f = new File(logFile);
    printStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(f)), true);
    System.setErr(printStream);
    System.setOut(printStream);
    System.out.println("Log started: " + new java.util.Date());When the virtual machine starts, System.out, a singleton object of type PrintStream, is hooked up to the console. You can then call print() and println() on this stream and have it show up there. Using System.setOut(), you can change this object and have it point somewhere else, such as a file. In this case, the variable log�File holds this location and becomes the output for the application.

Maybe you are looking for