Optimize 2>&1 in commands
Ilya Zakharevich [Thu, 10 Jun 1999 04:05:22 +0000 (00:05 -0400)]
Message-Id: <199906100805.EAA18216@monk.mps.ohio-state.edu>

p4raw-id: //depot/perl@3621

doio.c

diff --git a/doio.c b/doio.c
index 39e2e9f..7c093ae 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1126,6 +1126,20 @@ Perl_do_exec3(pTHX_ char *cmd, int fd, int do_report)
                *s = '\0';
                break;
            }
+           /* handle the 2>&1 construct at the end */
+           if (*s == '>' && s[1] == '&' && s[2] == '1'
+               && s > cmd + 1 && s[-1] == '2' && isSPACE(s[-2])
+               && (!s[3] || isSPACE(s[3])))
+           {
+               char *t = s + 3;
+
+               while (*t && isSPACE(*t))
+                   ++t;
+               if (!*t && (dup2(1,2) != -1)) {
+                   s[-2] = '\0';
+                   break;
+               }
+           }
          doshell:
            PerlProc_execl(PL_sh_path, "sh", "-c", cmd, (char*)0);
            return FALSE;