[tcljava-dev] A patch for exec and errorCode
Brought to you by:
mdejong
|
From: Mo D. <md...@cy...> - 2001-02-28 09:00:06
|
This patch is adapted from one sent in earlier.
Here is the Tcl behavior we want to match:
% catch {exec false} err
1
% set err
child process exited abnormally
% set errorCode
CHILDSTATUS 25301 1
Here is what the patched Jacl does:
% catch {exec false} err
1
% set err
child process exited abnormally
% set errorCode
CHILDSTATUS ?PID? 1
We don't have any way to find the
childs PID so I just put the
string ?PID? in there.
Here are a pair of test cases that
pass in Tcl and the patched Jacl.
test exec-4.1 { setting of errorCode when exit value != 0 } {
set abnormal {child process exited abnormally}
if {![catch {exec false} err]} {
set result "exception not raised"
} elseif {$err != $abnormal} {
set result "expected $abnormal got $err"
} elseif {[lindex $errorCode 0] != "CHILDSTATUS" ||
[lindex $errorCode 2] != "1"} {
set result "expected {CHILDSTATUS ?PID? 1} got $errorCode"
} else {
set result ok
}
} ok
test exec-4.2 { no error when exit value == 0 } {
list [catch {exec true} err] $err
} {0 {}}
And here is the patch:
Index: src/jacl/tcl/lang/ExecCmd.java
===================================================================
RCS file: /cvsroot/tcljava/tcljava/src/jacl/tcl/lang/ExecCmd.java,v
retrieving revision 1.5
diff -u -r1.5 ExecCmd.java
--- src/jacl/tcl/lang/ExecCmd.java 1999/05/17 03:50:37 1.5
+++ src/jacl/tcl/lang/ExecCmd.java 2001/02/28 08:59:32
@@ -151,6 +149,24 @@
sbuf.setLength(length - 1);
}
+ // Tcl supports lots of child status conditions.
+ // Unfortunately, we can only find the child's
+ // exit status using the Java API
+
+ if (exit != 0) {
+ TclObject childstatus = TclList.newInstance();
+ TclList.append(interp, childstatus,
+ TclString.newInstance("CHILDSTATUS"));
+
+ // We don't know how to find the child's pid
+ TclList.append(interp, childstatus,
+ TclString.newInstance("?PID?"));
+
+ TclList.append(interp, childstatus,
+ TclInteger.newInstance(exit));
+
+ interp.setErrorCode( childstatus );
+ }
//when the subprocess writes to its stderr stream or returns
//a non zero result we generate an error
Does anyone see any problems with this change?
Mo DeJong
Red Hat Inc
|