Run from command line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shoby
    New Member
    • Jul 2008
    • 9

    Run from command line

    Hi,

    i need to execute a bat file.

    i go to start->run and type the below line:

    cmd /C start "C:/Documents and Settings/Shoby/Desktop/CMTHome\bin\exe cute.bat"


    On doing the above all i get is the command window open.It does not execute the exe...

    Can someone help me with it??????
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by shoby
    Hi,

    i need to execute a bat file.

    i go to start->run and type the below line:

    cmd /C start "C:/Documents and Settings/Shoby/Desktop/CMTHome\bin\exe cute.bat"


    On doing the above all i get is the command window open.It does not execute the exe...

    Can someone help me with it??????
    What exe file? All I see is that you're starting a batch file in the background.
    Also type "help start" for an explanation for what you have been doing. And
    what was your Java question?

    kind regards,

    Jos

    Comment

    • shoby
      New Member
      • Jul 2008
      • 9

      #3
      I have a java code that executes the bat file containing the code to execute the exe. If the batch file is on the desktop the code does not work.ie; when i run the following code, the Command window appears but the batch file does not get executed.

      Runtime.getRunt ime().exec(cmd /C start "C:/Documents and Settings/Shoby/Desktop/CMTHome\bin\exe cute.bat");



      Any suggestions on how to solve this?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by shoby
        I have a java code that executes the bat file containing the code to execute the exe. If the batch file is on the desktop the code does not work.ie; when i run the following code, the Command window appears but the batch file does not get executed.

        Runtime.getRunt ime().exec(cmd /C start "C:/Documents and Settings/Shoby/Desktop/CMTHome\bin\exe cute.bat");



        Any suggestions on how to solve this?
        If you're using backslashes in that String you'd better double them; as in:

        [code=java]
        Runtime.getRunt ime().exec(cmd /C start "C:/Documents and Settings/Shoby/Desktop/CMTHome\\bin\\e xecute.bat");
        [/code]

        kind regards,

        Jos

        Comment

        • rajujrk
          New Member
          • Aug 2008
          • 107

          #5
          Better use the ProcessBuilder class to execute or open all file formats with the relevant open with application.

          Comment

          • chaarmann
            Recognized Expert Contributor
            • Nov 2007
            • 785

            #6
            Originally posted by shoby

            Runtime.getRunt ime().exec(cmd /C start "C:/Documents and Settings/Shoby/Desktop/CMTHome\bin\exe cute.bat");

            Any suggestions on how to solve this?
            In addition to what Jos has said, this source code would not compile anyway.

            there are double quotation marks missing in front of "cmd", and the quotation marks that you need inside the string because of the space in the folder name should be escaped this way: \"
            And then I would not mix Unix and Windows path separators (normal slashes and backslashes) in the pathname. And I would not even hardcode them, but use File.SEPARATOR instead.

            And why are you using "cmd" inside? I mean opening a shell that again opens a shell to execute your batch file, instead of executing it directly within a single shell?

            I mean if only one window opens and then nothing happens then the problem could be that the "cmd" is not found by the system and therefore the second shell does not open. Remember that "cmd" is a file in the windows system directory and its name is "cmd.exe". So either the path is missing to this file (check the environment variable PATH or better: just give the whole path), or windows does not know what to do if you just give "cmd" without extension ".exe". So instead of using "cmd", try to use something like "c:\\windows\\s ystem32\\cmd.ex e". (Or better, don't use it at all and execute .bat file directly.)

            Comment

            Working...