11 Replies Latest reply: Mar 17, 2011 5:06 AM by gimbal2 RSS

    Java output is not showing in the cmd but it is running in the backend

    847651
      Hi All,

      When I am running my java program from command prompt (cmd) in windows, then it is working fine.

      The output of the java program is not showing in the screen. But java is running in the background, as I can see in the task manager.

      Can anybody tell me that how can I get the output of the java program in the CMD?

      Thanks,
      S
        • 1. Re: Java output is not showing in the cmd but it is running in the backend
          aksarben
          How are you producing output? If you're using a logger, is it configured to send output to the console? If you're using printf(), has stdout been redirected? Show us code & we can give better answers.
          • 2. Re: Java output is not showing in the cmd but it is running in the backend
            baftos
            Do you execute java or javaw? It should be java.
            If it's not this, can it be that your program intentionally redirects the output elsewhere? It can be done.
            Put a System.out.println("hello") as your first line in main(String[] args). Do you at least see this output?
            • 3. Re: Java output is not showing in the cmd but it is running in the backend
              DarrylBurke
              Moderator action: Moved from Java Programming.
              Moderator advice: Please don't post beginner questions in Java Programming.

              db
              • 4. Re: Java output is not showing in the cmd but it is running in the backend
                DarrylBurke
                Posting a fresh question without bothering to reply to the responses on your earlier thread isn't exactly the best way to get help on a forum.
                Exception in thread "main" java.lang.NoClassDefFoundError:

                db
                • 5. Re: Java output is not showing in the cmd but it is running in the backend
                  847651
                  I am running the java file from one batch file called loadTables.bat.

                  The contents of the loadTables.bat file are below.

                  set CLASSPATH=C:\Tomcat 5.5\webapps\upd_stage_CX3_ZEUS\WEB-INF\lib\upd_configengine.jar;%CLASSPATH%
                  cd C:\Tomcat 5.5\webapps\upd_stage_CX3_ZEUS\WEB-INF\lib
                  java com.emc.upd.configengine.UPDTableGenerator -r "CX3_ZEUS"
                  • 6. Re: Java output is not showing in the cmd but it is running in the backend
                    847651
                    My code is using logger.

                    kindly find my code below.

                    public void createQuestionsTable(String releaseName)
                         throws Exception
                    {
                         UPDModelRelease updModelRelease = (UPDModelRelease)this.modelDef.getUPDModelReleases().get(releaseName);
                         log.info("createQuestionsTable(): Starting...");
                         List modelAttributeIds = updModelRelease.getModelAttributeIDs();
                         log.info("createQuestionsTable(): Retrieved list of model attribute ids");
                    String environment = this.modelDef.getEnvironment();
                         log.info("createQuestionsTable(): Updating environment " + environment);
                    if (modelAttributeIds != null)
                    {
                         log.info("createQuestionsTable(): modelAttributes is not null.");
                         //First see if table already exists for this environment and releaseName
                         if (DBHelper.questionsTableExists(this.modelDef.getDBParameters(),environment, releaseName))
                         {
                         log.info("createQuestionsTable(): Table already exists. Need to create archive.");           
                              DBHelper.createQuestionsTableArchive(this.modelDef.getDBParameters(),environment, releaseName);
                         }
                         log.info("createQuestionsTable(): About to create questions table.");      
                              DBHelper.createQuestionsTable(this.modelDef.getDBParameters(),environment, releaseName, modelAttributeIds);
                    }
                    else
                    {
                         log.error("createQuestionsTable(): Unable to create questions table - no attributes.");
                         throw new Exception("Unable to create questions table - no attributes.");
                    }
                    }
                    • 7. Re: Java output is not showing in the cmd but it is running in the backend
                      gimbal2
                      yes, so how is this logger configured? If it goes to a file you are not going to see the output in your command window. Or worse: it might be configured to use some kind of NOP logger.
                      • 8. Re: Java output is not showing in the cmd but it is running in the backend
                        DarrylBurke
                        Cross posted
                        http://www.java-forums.org/advanced-java/40665-java-output-not-showing-cmd-but-running-backend.html

                        db
                        • 9. Re: Java output is not showing in the cmd but it is running in the backend
                          847651
                          Hi,

                          Kindly see me code for how the logger is configured. Here we are using log4j.logger and from log4j.properties it is taking.


                          import java.io.IOException;
                          import java.util.Iterator;
                          import java.util.List;
                          import java.util.ArrayList;
                          import com.emc.upd.utility.DBHelper;
                          import org.apache.log4j.Logger;


                          /**
                          * @author dmadmin
                          *
                          * TODO To change the template for this generated type comment go to
                          * Window - Preferences - Java - Code Style - Code Templates
                          */
                          public class UPDTableGeneratorSunita {

                          private static Logger log = Logger.getLogger( "UPDTableGenerator" );
                          private UPDModelDefinition modelDef;
                          private int count;

                          public UPDTableGeneratorSunita ( UPDModelDefinition modelDef ) {
                          this.modelDef = modelDef;
                          this.count = 0;
                          }

                          public void createQuestionsTable(String releaseName)
                               throws Exception
                          {
                               UPDModelRelease updModelRelease = (UPDModelRelease)this.modelDef.getUPDModelReleases().get(releaseName);
                               log.info("createQuestionsTable(): Starting...");
                               List modelAttributeIds = updModelRelease.getModelAttributeIDs();
                               log.info("createQuestionsTable(): Retrieved list of model attribute ids");
                          String environment = this.modelDef.getEnvironment();
                               log.info("createQuestionsTable(): Updating environment " + environment);
                          if (modelAttributeIds != null)
                          {
                               log.info("createQuestionsTable(): modelAttributes is not null.");
                               //First see if table already exists for this environment and releaseName
                               if (DBHelper.questionsTableExists(this.modelDef.getDBParameters(),environment, releaseName))
                               {
                               log.info("createQuestionsTable(): Table already exists. Need to create archive.");           
                                    DBHelper.createQuestionsTableArchive(this.modelDef.getDBParameters(),environment, releaseName);
                               }
                               log.info("createQuestionsTable(): About to create questions table.");      
                                    DBHelper.createQuestionsTable(this.modelDef.getDBParameters(),environment, releaseName, modelAttributeIds);
                          }
                          else
                          {
                               log.error("createQuestionsTable(): Unable to create questions table - no attributes.");
                               throw new Exception("Unable to create questions table - no attributes.");
                          }
                          }

                          public static boolean validateReleaseName(String releaseName)throws Exception
                          {
                               boolean releaseNameValidity = false;      
                               log.info("validateReleaseName(): Starting...");     
                               ArrayList releases = UPDModelParser.getSupportedReleases();      
                               if (releases.contains(releaseName))
                               releaseNameValidity = true;      
                               return releaseNameValidity;
                          }

                          public static void main( String args[] ) {         
                               String releaseName = null;      
                               boolean releaseNameProvided = false;
                               log.info("main(): Starting...");
                                    for (int i=0; i < args.length; i++)
                                    {
                                         if (args.equalsIgnoreCase("-r"))
                                         {
                                              releaseName = args[++i];
                                              releaseNameProvided = true;
                                         }
                                    }
                                    try
                                    {
                                         if (releaseNameProvided)
                                         {
                                         log.info("main(): Release name provided: releaseName = " + releaseName);
                                              boolean releaseNameValid = validateReleaseName(releaseName);
                                              if (releaseNameValid)
                                              {
                                                   UPDModelDefinition modelDef = UPDModelParser.parse();
                                                   log.info("main(): created UPDModelDefinition");
                                                   UPDTableGeneratorSunita tableGen = new UPDTableGeneratorSunita( modelDef );
                                                   tableGen.createQuestionsTable(releaseName);                         
                                              }
                                              else
                                              {
                                                   log.error("main(): Invalid release parameter value. It does not exist in upd_generation.xml file.");
                                                   System.out.println(" Invalid release parameter value. It does not exist in upd_generation.xml file. \n");
                                                   System.out.println(" Usage: java com.emc.upd.UPDTableGenerator [-r releaseName] ");
                                              }
                                         }
                                         else
                                         {
                                              log.error("main(): Invalid command line.");
                                              System.out.println(" Invalid command line. \n");
                                              System.out.println(" Usage: java com.emc.upd.UPDTableGenerator [-r releaseName] ");
                                         }
                                         
                                         log.info("successfully created three tables (Question, PDF and Legend) in the database.");
                                    }
                                    catch(Exception e)
                                    {
                                         log.error("main(): Error encountered: " + e.getLocalizedMessage());
                                         System.out.println(" Error encountered: " + e.getLocalizedMessage());
                                    }
                          }
                          }
                          • 10. Re: Java output is not showing in the cmd but it is running in the backend
                            DarrylBurke
                            Moderator advice: Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose.

                            Then edit your post and format the code correctly.

                            db
                            • 11. Re: Java output is not showing in the cmd but it is running in the backend
                              gimbal2
                              Let me get this straight. You want people to check out the logger configuration. Which is in the log4j.properties file as you state yourself. And then you post more code.

                              Are you deliberately making it difficult for you to be helped? I'm already tired of this, I suggest you make an effort yourself. Read the log4j manual!