Linux Run time coammnd error in Java.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Linux Run time coammnd error in Java.

    I am trying run a command in Java,which runs in console of Linux properly.
    But while I am trying to run in Java then it flushes errors.
    What might be the possible reasons?

    The command follows..
    keytool -genkey -keyalg RSA -dname "CN=DEBASISBHAT TACHARYYA, OU=MS, O=IIT, C=IN" -validity 24 -alias debasis -keypass password -keystore /DATA/keystore/userkey/E84009.jks -storepass password

    And the error ..what i m getting is ...
    keytool error: java.lang.Runti meException: Usage error, OU=MS, is not a legal command

    Please help me.
    it's urgent!
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    How did you handle those double quotes in Java?

    kind regards,

    Jos

    ps. I fixed those bold tags for you; please preview your post before hitting submit.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by JosAH
      How did you handle those double quotes in Java?

      kind regards,

      Jos

      ps. I fixed those bold tags for you; please preview your post before hitting submit.
      As it supposed to be handled ...
      using \" ... :-)
      Am i wrong?
      One more thing ... it is running properly in windows platform.
      please suggest ..it's urgent on tomorrow!

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by dmjpro
        As it supposed to be handled ...
        using \" ... :-)
        Am i wrong?
        please suggest ..it's urgent on tomorrow!
        Don't mention that it's urgent; it may be urgent to you but it isn't for me nor anyone
        else. Can you show a bit of relevant code?

        kind regards,

        Jos

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by JosAH
          Don't mention that it's urgent; it may be urgent to you but it isn't for me nor anyone
          else. Can you show a bit of relevant code?

          kind regards,

          Jos
          Yeah sorry!!!

          [code=java]
          String command = "keytool -genkey -dname \"CN=" +
          keyStoreInfo.ge tCommon_name() + ", OU=" + keyStoreInfo.ge tOrganizational _unit() +
          ", O=" + keyStoreInfo.ge tOrganization() + ", C=" + keyStoreInfo.ge tCountry() + "\"" +
          " -alias " + keyStoreInfo.ge tAlias() +
          " -keypass " + keyStoreInfo.ge tAlias_password () + " -keystore " + keyStoreFilePat h +
          " -storepass " + keyStoreInfo.ge tKeyStorePasswo rd() + " -validity " + keyStoreInfo.ge tValidity() +
          " -keyalg RSA";

          System.out.prin tln("Command : " + command);
          isGenerated = runCommand(comm and);
          [/code]

          This is the runCommand method....
          [code=java]
          boolean runCommand(Stri ng command) {
          boolean isCompleted = false;

          try {
          Process p = Runtime.getRunt ime().exec(comm and);
          p.waitFor();
          BufferedReader stdError = new BufferedReader( new InputStreamRead er(p.getErrorSt ream()));
          //proc=rt.exec("k eytool -list -keystore keystore -storepass storepass");
          BufferedReader stdInput = new BufferedReader( new InputStreamRead er(p.getInputSt ream()));
          //proc=rt.exec("k eytool -list -keystore keystore -storepass storepass");
          String s = null;

          while ((s = stdInput.readLi ne()) != null) {
          System.out.prin tln(s);
          }
          if (stdError == null) {

          } else {
          while ((s = stdError.readLi ne()) != null) {
          System.out.prin tln(s);
          }

          }
          isCompleted = true;
          } catch (InterruptedExc eption ex) {
          isCompleted = false;
          Logger.getLogge r(KeyStoreGener ation.class.get Name()).log(Lev el.SEVERE, null, ex);
          } catch (IOException ex) {
          isCompleted = false;
          Logger.getLogge r(KeyStoreGener ation.class.get Name()).log(Lev el.SEVERE, null, ex);
          }
          return isCompleted;
          }
          [/code]

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            In your runCommand() method, print out that command String and see what it is
            actually trying to exec.

            kind regards,

            Jos

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by JosAH
              In your runCommand() method, print out that command String and see what it is
              actually trying to exec.

              kind regards,

              Jos

              I am simply pass the command parameter.
              Is there any chance to loose characters?
              Why should i check that out as we copy the printed command
              [code=java]
              System.out.prin tln("Command : " + command);
              [/code]
              and paste the command to console and it runs properly.
              What might be the reasons?

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by dmjpro
                I am simply pass the command parameter.
                Is there any chance to loose characters?
                Why should i check that out as we copy the printed command
                [code=java]
                System.out.prin tln("Command : " + command);
                [/code]
                and paste the command to console and it runs properly.
                What might be the reasons?
                Just to be sure; what did it print? Was it the correct command string?

                kind regards,

                Jos

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by JosAH
                  Just to be sure; what did it print? Was it the correct command string?

                  kind regards,

                  Jos
                  Josh I solved that problem.
                  Actually I read this link ...
                  Runtime.exec() pifalls and came to know the reality.
                  I used command array instead of using the whole command in a single string.
                  Thanks for your help Josh.

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by dmjpro
                    Josh I solved that problem.
                    Actually I read this link ...
                    Runtime.exec() pifalls and came to know the reality.
                    I used command array instead of using the whole command in a single string.
                    Thanks for your help Josh.
                    From what I can see from your posts above you were using a single String for
                    your command, not an array; so what's up?

                    kind regards,

                    Jos

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Originally posted by JosAH
                      From what I can see from your posts above you were using a single String for
                      your command, not an array; so what's up?

                      kind regards,

                      Jos

                      I posted it in my 3rd post in dis thread.
                      Anyway now the picture runtime.exec cum to me.
                      Thanks for kind help!

                      Comment

                      Working...