1 2 Previous Next 20 Replies Latest reply on May 27, 2008 3:57 AM by EJP Go to original post
      • 15. Re: Stuck On Runtime.exec() with cmd.exe
        843790
        DarioAtUOW wrote:
        How bizzarre. I copied over the code from the JavaWorld article Listing 4.3 strainght into my code and commented out all of my problem code.

        java.io.IOException: Cannot run program "javac": CreateProcess error=2, The system cannot find the file specified.
        So as I expected you had not implemented all the recommendations from the JavaWorld article.
        • 16. Re: Stuck On Runtime.exec() with cmd.exe
          843790
          Well, what I was trying to get at there was that at least in the article, he was able to get some output, where as mine can't even do that. If you copy and paste an example, you should get the same output as the example got :

          Quote from the article :

          A run of MediocreExecJavac generates:
          E:\classes\com\javaworld\jpitfalls\article2>java MediocreExecJavac
          <ERROR>
          Usage: javac <options> <source files>
          where <options> includes:
          -g Generate all debugging info
          -g:none Generate no debugging info
          -g:{lines,vars,source} Generate only some debugging info
          -O Optimize; may hinder debugging or enlarge class files
          -nowarn Generate no warnings
          -verbose Output messages about what the compiler is doing
          -deprecation Output source locations where deprecated APIs are used
          -classpath <path> Specify where to find user class files
          -sourcepath <path> Specify where to find input source files
          -bootclasspath <path> Override location of bootstrap class files
          -extdirs <dirs> Override location of installed extensions
          -d <directory> Specify where to place generated class files
          -encoding <encoding> Specify character encoding used by source files
          -target <release> Generate class files for specific VM version
          </ERROR>
          Process exitValue: 2



          So, MediocreExecJavac works and produces an exit value of 2. Normally, an exit value of 0 indicates success; any nonzero value indicates an error. The meaning of these exit values depends on the particular operating system. A Win32 error with a value of 2 is a "file not found" error. That makes sense, since javac expects us to follow the program with the source code file to compile.

          Edited by: DarioAtUOW on May 26, 2008 7:13 AM
          • 17. Re: Stuck On Runtime.exec() with cmd.exe
            843790
            DarioAtUOW wrote:
            Well, what I was trying to get at there was that at least in the article, he was able to get some output, where as mine can't even do that. If you copy and paste an example, you should get the same output as the example got :

            Quote from the article :

            A run of MediocreExecJavac generates:
            E:\classes\com\javaworld\jpitfalls\article2>java MediocreExecJavac
            <ERROR>
            Usage: javac <options> <source files>
            where <options> includes:
            -g Generate all debugging info
            -g:none Generate no debugging info
            -g:{lines,vars,source} Generate only some debugging info
            -O Optimize; may hinder debugging or enlarge class files
            -nowarn Generate no warnings
            -verbose Output messages about what the compiler is doing
            -deprecation Output source locations where deprecated APIs are used
            -classpath <path> Specify where to find user class files
            -sourcepath <path> Specify where to find input source files
            -bootclasspath <path> Override location of bootstrap class files
            -extdirs <dirs> Override location of installed extensions
            -d <directory> Specify where to place generated class files
            -encoding <encoding> Specify character encoding used by source files
            -target <release> Generate class files for specific VM version
            </ERROR>
            Process exitValue: 2



            So, MediocreExecJavac works and produces an exit value of 2. Normally, an exit value of 0 indicates success; any nonzero value indicates an error. The meaning of these exit values depends on the particular operating system. A Win32 error with a value of 2 is a "file not found" error. That makes sense, since javac expects us to follow the program with the source code file to compile.
            Sorry but I'm missing your point.

            I have used Runtime.exec() for a number of years on Windows 2000 and XP and on Linux. The single most important concern that I have found is that one makes sure one processes the Process stdout and stderr in separate threads. One might get away without processing stderr but not processing stderr will one day bite you hard.

            The second biggest concern is in the use of a single String to hold the command since this can lead to problems when file names have spaces. If one sticks to using a command using a String[] then this is no longer a problem.
            • 18. Re: Stuck On Runtime.exec() with cmd.exe
              843790
              I spoke too soon (or too sleepily last night) but it doesn't actually work for me. I have run Listing 4.8 that is supposed to be the best way possible to call programs. I used the "cmd.exe dir" instead of the Netscape command. What I get is :


              init:
              deps-jar:
              Compiling 1 source file to C:\Users\Dario\Documents\NetBeansProjects\Learning NetBeans\build\classes
              compile:
              run:
              cmd.exe dir
              OUT>Microsoft Windows [Version 6.0.6000]
              OUT>Copyright (c) 2006 Microsoft Corporation. All rights reserved.
              OUT>

              So, it freezes forever before getting to the actual listing of the directory. Should I do a bug report to Sun about this on Vista ?

              Edited by: DarioAtUOW on May 26, 2008 8:30 PM
              • 19. Re: Stuck On Runtime.exec() with cmd.exe
                843790
                Spoke too soon.
                • 20. Re: Stuck On Runtime.exec() with cmd.exe
                  EJP
                  I used the "cmd.exe dir"
                  You keep talking about that as though it is a legal way to invoke the 'dir' command. It isn't.
                  cmd.exe dir
                  OUT>Microsoft Windows [Version 6.0.6000]
                  OUT>Copyright (c) 2006 Microsoft Corporation. All rights reserved.
                  OUT>
                  That's exactly what I get (without the OUT>) when I run 'cmd.exe dir' at the command prompt. So if you get that when running via Runtime.exec() you don't have anything to complain about.

                  What you mean is 'cmd.exe /c dir' ...
                  1 2 Previous Next