On Tue, 4 May 1999, Steve Byrne wrote:
> Scott Murray writes:
[snip]
> > It seems to fix the problem I (and others I think) had with Runtime.exec
> > hanging sometimes when used with native threads. Which is good, as I
> > was almost resigned to putting in some Linux specific code into the app
> > I'm working on to avoid the problem under v1a.
>
> What kind of hanging? Were you waiting for the process to complete explicitly?
> I'm very interested to find out more.
>
> We're having that problem in 1.2 with native threads, which is one of the
> reasons that we don't say we pass JCK using native threads yet.
I'm attaching the source to my test program below as it's pretty short. It's
something I pasted together with code snippets from the Java Programmer's
FAQ as a proof-of-concept Solaris JDK 1.2 version checker, so it's not the
greatest code in the world. I do call Process.waitFor(), but it's probably
unnecessary, as I imagine that the exec'd Process is already dead when its
stderr is closed.
Under jdk117_v1a with native threads, the program hangs at the first
readLine call, but it works fine when run with the pre-release jdk117_v2 or
with jdk1.2pre-v1. That it works with jdk1.2pre-v1 makes me suspect that it
might not be of much use to you for debugging purposes, but you never know.
Scott
--
=============================================================================
Scott Murray email: [EMAIL PROTECTED]
http://www.interlog.com/~scottm ICQ#: 10602428
-----------------------------------------------------------------------------
"Good, bad ... I'm the guy with the gun." - Ash, "Army of Darkness"
import java.io.*;
import java.util.*;
class CheckVersion {
public static void main(String[] args) {
boolean valid = false;
String path = "/usr/local/jdk1.2/bin/java";
if(args.length >= 1) {
path = args[0];
}
String command[] = { path, "-version" };
//String command = path + " -version";
System.out.println("executing command: " + path + " -version");
try {
System.out.println("Before exec");
Process p = Runtime.getRuntime().exec(command);
System.out.println("After exec");
BufferedReader pErr = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
System.out.println("Reader created");
// Get stderr
String s = pErr.readLine();
System.out.println("Read output line: " + s);
String last = s;
while (s != null) {
last = s;
s = pErr.readLine();
System.out.println("Read output line: " + s);
}
//For testing: String last = null;
p.waitFor();
System.out.println("Command return code = " + p.exitValue());
if(last != null) {
System.out.println("Last line output: " + last);
StringTokenizer st = new StringTokenizer(last);
String type = null;
if(st.hasMoreTokens()) {
type = st.nextToken();
}
if(type != null) {
System.out.println("vm type = " + type);
if(type.equals("Classic")) {
valid = true;
}
}
}
}
catch (Exception e) { }
if(valid) {
System.out.println("Valid 1.2 VM version.");
}
else {
System.out.println("Invalid 1.2 VM version!");
}
}
}