I added [code] tags to your previous post to make the indentation readable. So, you read the Daconta article. Did you try the code? One thing you may not realize is that StreamGobbler actually runs in a separate thread. This can be important. With the code you show, it's possible that the error stream's buffer is full with some message for you, but you're waiting to read from standard output first.
This creates a hang, since the process remains open and thus the standard output does not return null, at least until the error message has been read.
It's definitely a good idea to use StreamGobbler or something like it. Listing 4. While this approach will work, it is not a good general solution.
Thus, Listing 4. A better solution would empty both the standard error stream and the standard output stream. And the best solution would empty these streams simultaneously I'll demonstrate that later.
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. Thus, to circumvent the second pitfall -- hanging forever in Runtime. Under the Windows operating system, many new programmers stumble upon Runtime. Subsequently, they run into Runtime. As stated earlier, the error value of 2 means "file not found," which, in this case, means that the executable named dir. That's because the directory command is part of the Windows command interpreter and not a separate executable.
To run the Windows command interpreter, execute either command. Here are the latest Insider stories. More Insider Sign Out.
Sign In Register. Sign Out Sign In Register. Latest Insider. Check out the latest Insider stories here. More from the IDG Network. How to use Java generics to avoid ClassCastExceptions. Java Elementary language features. Fill in your details below or click an icon to log in:.
Email required Address never made public. Name required. Follow Following. The real stuff. Sign me up. Already have a WordPress. Log in now. Post was not sent - check your email addresses! Sorry, your blog cannot share posts by email.
0コメント