From 96aa251ca0a6b772efbfd198f2b6803c2c1ae721 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sat, 25 Mar 2023 02:00:50 +0100 Subject: [PATCH] fix execute tcl procedure (correctly handle exit status of subprocesses that write to stderr but not as a failure) --- src/scheduler.c | 1 + src/xschem.tcl | 29 +++++++------------------- xschem_library/ngspice/solar_panel.sch | 6 ++---- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index 14813339..84feca06 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -3389,6 +3389,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(argc > 2) tclvareval("simulate ", argv[2], NULL); else tcleval("simulate"); } + Tcl_ResetResult(interp); } /* snap_wire diff --git a/src/xschem.tcl b/src/xschem.tcl index c2676b7e..46626e21 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -216,28 +216,15 @@ proc execute_fileevent {id} { # do not ask status for processes that close stdout/stderr, as eof might # occur before process ends and following close blocks until process terminates. fconfigure $execute(pipe,$id) -blocking 1 - set status 0 - if { [ info tclversion] > 8.4} { - set catch_return [eval catch [list {close $execute(pipe,$id)} err options] ] - } else { - set catch_return [eval catch [list {close $execute(pipe,$id)} err] ] - } + set exit_status 0 + set catch_return [eval catch [list {close $execute(pipe,$id)} err] ] if {$catch_return} { - if {[info tclversion] > 8.4} { - set details [dict get $options -errorcode] - if {[lindex $details 0] eq "CHILDSTATUS"} { - set status [lindex $details 2] - if {$report} {viewdata "Failed: $execute(cmd,$id)\nstderr:\n$err\ndata:\n$execute(data,$id)"} - } else { - set status 1 - if {$report} {viewdata "Completed: $execute(cmd,$id)\nstderr:\n$err\ndata:\n$execute(data,$id)"} - } - } else { - set status 1 - if {$report} {viewdata "Completed: $execute(cmd,$id)\nstderr:\n$err\ndata:\n$execute(data,$id)"} + global errorCode + if {"CHILDSTATUS" == [lindex $errorCode 0]} { + set exit_status [lindex $errorCode 2] } - } - if {$status == 0} { + if {$report} {viewdata "Completed: $execute(cmd,$id)\nstderr:\n$err\ndata:\n$execute(data,$id)"} + } else { if {$report} {viewdata "Completed: $execute(cmd,$id)\ndata:\n$execute(data,$id)"} } if {[info exists execute(callback,$id)] && $execute(callback,$id) ne {}} { @@ -248,7 +235,7 @@ proc execute_fileevent {id} { set execute(data,last) $execute(data,$id) set execute(error,last) $err set execute(status,last) $execute(status,$id) - set execute(exitcode,last) $status + set execute(exitcode,last) $exit_status unset execute(pipe,$id) unset execute(data,$id) unset execute(status,$id) diff --git a/xschem_library/ngspice/solar_panel.sch b/xschem_library/ngspice/solar_panel.sch index 9926408d..48e794c1 100644 --- a/xschem_library/ngspice/solar_panel.sch +++ b/xschem_library/ngspice/solar_panel.sch @@ -227,13 +227,11 @@ lab=TRIANG} N 820 -280 820 -160 { lab=0} C {title.sym} 160 -40 0 0 {name=l1 author="Stefan Schippers" net_name=true} -C {code_shown.sym} 190 -250 0 0 {name=CONTROL value="* following line for batch mode... -.tran .05u 1m uic -* following block for interactive mode -.control +C {code_shown.sym} 190 -250 0 0 {name=CONTROL value=".control * save all tran .05u 1m uic write solar_panel.raw +exit .endc " net_name=true} C {code.sym} 20 -190 0 0 {name=MODELS value=".MODEL DIODE D(IS=1.139e-08 RS=0.99 CJO=9.3e-12 VJ=1.6 M=0.411 BV=30 EG=0.7 )