diff options
-rw-r--r-- | doc/jim_tcl.txt | 6 | ||||
-rw-r--r-- | jim-exec.c | 26 | ||||
-rw-r--r-- | tests/exec.test | 4 |
3 files changed, 28 insertions, 8 deletions
diff --git a/doc/jim_tcl.txt b/doc/jim_tcl.txt index fa900f9..281817b 100644 --- a/doc/jim_tcl.txt +++ b/doc/jim_tcl.txt @@ -60,7 +60,7 @@ CHANGES ------- Since v0.61: -1. Add support to 'exec' for '>&', '>>&', '|&' +1. Add support to 'exec' for '>&', '>>&', '|&', '2>@1' 2. Fix 'exec' error messages when special token (e.g. '>') is the last token 3. Fix 'subst' handling of backslash escapes. 4. Allow abbreviated options for 'subst' @@ -1760,6 +1760,10 @@ An *arg* may have one of the following special forms: The standard error of the last command in the pipeline is redirected to the given (writable) file descriptor. ++2>@1+:: + The standard error of the last command in the pipeline is + redirected to the same file descriptor as the standard output. + +>&filename+:: Both the standard output and standard error of the last command in the pipeline is redirected to the file. @@ -693,14 +693,26 @@ Jim_CreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int **pid /* If we are redirecting stderr with 2>filename or 2>@fileId, then we ignore errFilePtr */ if (error != NULL) { if (errorFile == FILE_HANDLE) { - Jim_Obj *fhObj = Jim_NewStringObj(interp, error, -1); - FILE *fh = Jim_AioFilehandle(interp, fhObj); - Jim_FreeNewObj(interp, fhObj); - if (fh == NULL) { - goto error; + if (strcmp(error, "1") == 0) { + /* Special 2>@1 */ + if (lastOutputId >= 0) { + errorId = dup(lastOutputId); + } + else { + /* No redirection stdout, so just use 2>@stdout */ + error = "stdout"; + } + } + if (errorId < 0) { + Jim_Obj *fhObj = Jim_NewStringObj(interp, error, -1); + FILE *fh = Jim_AioFilehandle(interp, fhObj); + Jim_FreeNewObj(interp, fhObj); + if (fh == NULL) { + goto error; + } + fflush(fh); + errorId = dup(fileno(fh)); } - fflush(fh); - errorId = dup(fileno(fh)); } else { /* diff --git a/tests/exec.test b/tests/exec.test index f37b5fb..47b246f 100644 --- a/tests/exec.test +++ b/tests/exec.test @@ -454,6 +454,10 @@ test exec-15.6 {standard error redirection} { >& gorp.file 2> gorp.file2 | echo biz baz list [exec cat gorp.file] [exec cat gorp.file2] } {{biz baz} {foo bar}} +test exec-15.7 {combine standard output/standard error} { + exec sh -c "echo foo bar 1>&2" > gorp.file 2>@1 + exec cat gorp.file +} {foo bar} test exec-16.1 {flush output before exec} { set f [open gorp.file w] |