Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7769959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:17:20+00:00 2026-06-01T16:17:20+00:00

Is there any way I can save all the things that is happening on

  • 0

Is there any way I can save all the things that is happening on my Windows 7 Command Prompt in a file. So that I can see what are the things that got printed on the console. I am running a multithreaded Java Program from the command prompt as-

java -server -Xms512m -Xmx512m -XX:PermSize=512m -XX:MaxPermSize=512m -Duser.timezone=GMT-7 –jar BatchMain.jar -taskId V3-PERSONALIZATIONGEO-SAMPLE-TASK -noofthreads 1 -timeout 5 -numberOfIP 1000 -privateIPAddress false

And it prints lot of things on to the command prompt, And I want to store all these things that are getting printed on the console into a file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:17:22+00:00Added an answer on June 1, 2026 at 4:17 pm

    You can either capture the output directly in your program, or on the console.

    On the console

    If you want to get absolutely everything (both STDOUT and STDERR), you need to redirect STDOUT (from System.out) and STDERR (from System.err). You can either redirect both to the same file (add > log.txt 2>&1 to the end of your console command), or you can log them to different files (add > BatchMain.log 2> BatchMain.err to the end of your console).

    Log to a single file, log.txt:

    java -server -Xms512m -Xmx512m -XX:PermSize=512m -XX:MaxPermSize=512m -Duser.timezone=GMT-7 –jar BatchMain.jar -taskId V3-PERSONALIZATIONGEO-SAMPLE-TASK -noofthreads 1 -timeout 5 -numberOfIP 1000 -privateIPAddress false > log.txt 2>&1
    

    Log to separate files, BatchMain.log and BatchMain.err:

    java -server -Xms512m -Xmx512m -XX:PermSize=512m -XX:MaxPermSize=512m -Duser.timezone=GMT-7 –jar BatchMain.jar -taskId V3-PERSONALIZATIONGEO-SAMPLE-TASK -noofthreads 1 -timeout 5 -numberOfIP 1000 -privateIPAddress false > BatchMain.log 2> BatchMain.err
    

    Directly within your program

    In your main(String[] args) method (or some other appropriate place), set System.out and System.err to print directly to files (or the same file, if you wish). For example:

    package com.example.logging;
    
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.PrintStream;
    
    public class LogToFiles {
    
        public static void main(String[] args) throws FileNotFoundException {
            System.setOut(new PrintStream("example.log"));
            System.setErr(new PrintStream(new FileOutputStream("example.err"), true));
    
            System.out.println("System.out example");
            System.err.println("System.err example");
        }
    
    }
    

    If you want the output to also be visible on the console, you can go a step further and insert your own intermediate PrintStream which does this.

    Other things to consider

    Note that Java buffers System.out, so if you log both STDOUT and STDERR to the same file, you could end up with nonsensical output that has the two PrintStreams interwoven, or something in STDOUT could be printed much later than a related message that was printed to STDERR. One workaround is to call System.out.flush() as appropriate, but this could degrade performance if you’re logging a lot of text to System.out.

    Rather than printing everything to the console with System.out.println() and trying to capture that output, I’d recommend using Java Logging or Log4J, or going a step further and using Apache Commons Logging, which can be configured to use either of the first two systems internally. The really awesome part is that you don’t have to divine which class printed each log message, because you’ll get that automatically.

    If you use a logging framework, you can also adjust the verbosity of your logging output by setting a single variable–which will come in handy at release time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can force Visual Studio (2010) to save all files
Is there any way I can set a formatter on models that will convert
Is there any way can declare a bean in just like JSP UseBean in
Is there any way we can fetch X509 Public Cetrificates using c# from AD
Is there any way I can use JPA or hibernate annotations to specify the
Is there any way I can do Select TableName.SomeColumn As SomeAlias FROM TableName In
Is there any way I can use RegExp or Wildcard searches to quickly delete
Is there any way I can run class files (i.e. with main as the
Is there any way I can add a static extension method to a class.
Is there any way I can find out in my app if the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.