diff options
author | Steve Bennett <steveb@workware.net.au> | 2016-09-14 14:15:47 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2017-10-17 07:39:39 +1000 |
commit | 1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5 (patch) | |
tree | 78c2baa61687fa296dc418cd1b978b3e046813f6 /tclcompat.tcl | |
parent | 4be55f10c4d2071f493b9a1b60197c5e20f3203d (diff) | |
download | jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.zip jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.tar.gz jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.tar.bz2 |
signal, exec, wait, pid: improvements, especially to exec
- fix popen [open "|pipeline ..."] to return meaningful status in close
(but note that stderr is not captured)
- popen pipelines can now be used as the target of exec redirection
- overally improvements to exec on windows. Now crt file descriptors
are used throughout
- add support for [pid], [wait] and popen on windows
- os.wait is now wait, and integrates with [exec ... &] to be able
to wait for running background tasks
- [socket pipe] is now also [pipe] and is supported on windows
- [file tempfile] is supported on windows
- move duplicated code between jim-aio.c and jim-exec.c to jimiocompat.c
- Fix [exec] on windows to match unix semantics wrt sharing the parent stream
unless redirected rather than using /dev/null
- On windows redirect to or from /dev/null is automatically converted to NUL:
- If signal support is disabled, implement a minimal Jim_SignalId() for exec and wait
- aio now supports getfd, to return the underlying file descriptor.
This is used by exec to support redirection, and allows popen channels
to support exec redirection.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tclcompat.tcl')
-rw-r--r-- | tclcompat.tcl | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/tclcompat.tcl b/tclcompat.tcl index e2ae56e..b3452d8 100644 --- a/tclcompat.tcl +++ b/tclcompat.tcl @@ -120,7 +120,7 @@ proc {file copy} {{force {}} source target} { # 'open "|..." ?mode?" will invoke this wrapper around exec/pipe # Note that we return a lambda which also provides the 'pid' command proc popen {cmd {mode r}} { - lassign [socket pipe] r w + lassign [pipe] r w try { if {[string match "w*" $mode]} { lappend cmd <@$r & @@ -137,11 +137,26 @@ proc popen {cmd {mode r}} { if {$cmd eq "pid"} { return $pids } + if {$cmd eq "getfd"} { + $f getfd + } if {$cmd eq "close"} { $f close # And wait for the child processes to complete - foreach p $pids { os.wait $p } - return + set retopts {} + foreach p $pids { + lassign [wait $p] status - rc + if {$status eq "CHILDSTATUS"} { + if {$rc == 0} { + continue + } + set msg "child process exited abnormally" + } else { + set msg "child killed: received signal" + } + set retopts [list -code error -errorcode [list $status $p $rc] $msg] + } + return {*}$retopts } tailcall $f $cmd {*}$args } |