aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-01-27 14:11:42 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:46 +1000
commit88694720353f9c0ad65f8e2ce31d5e1b645474d6 (patch)
tree7507948ca4cff46dad44d75e8e3ce39b59c7f31f
parent82fcf63727049e8b97238ca8e419d3ea96d304a0 (diff)
downloadjimtcl-88694720353f9c0ad65f8e2ce31d5e1b645474d6.zip
jimtcl-88694720353f9c0ad65f8e2ce31d5e1b645474d6.tar.gz
jimtcl-88694720353f9c0ad65f8e2ce31d5e1b645474d6.tar.bz2
Add exec support for 2>@1
See TIP #202: http://www.tcl.tk/cgi-bin/tct/tip/202.html
-rw-r--r--doc/jim_tcl.txt6
-rw-r--r--jim-exec.c26
-rw-r--r--tests/exec.test4
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.
diff --git a/jim-exec.c b/jim-exec.c
index 4ad9b21..4d3364c 100644
--- a/jim-exec.c
+++ b/jim-exec.c
@@ -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]