Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / lisp / eshell / esh-proc.el
index a838da3..675f422 100644 (file)
@@ -1,16 +1,16 @@
 ;;; esh-proc.el --- process management
 
 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
+;;; Code:
+
 (provide 'esh-proc)
 
 (eval-when-compile
@@ -238,10 +238,30 @@ The prompt will be set to PROMPT."
   "A marker that tracks the beginning of output of the last subprocess.
 Used only on systems which do not support async subprocesses.")
 
+(defvar eshell-needs-pipe '("bc")
+  "List of commands which need `process-connection-type' to be nil.
+Currently only affects commands in pipelines, and not those at
+the front.  If an element contains a directory part it must match
+the full name of a command, otherwise just the nondirectory part must match.")
+
+(defun eshell-needs-pipe-p (command)
+  "Return non-nil if COMMAND needs `process-connection-type' to be nil.
+See `eshell-needs-pipe'."
+  (and eshell-in-pipeline-p
+       (not (eq eshell-in-pipeline-p 'first))
+       ;; FIXME should this return non-nil for anything that is
+       ;; neither 'first nor 'last?  See bug#1388 discussion.
+       (catch 'found
+        (dolist (exe eshell-needs-pipe)
+          (if (string-equal exe (if (string-match "/" exe)
+                                    command
+                                  (file-name-nondirectory command)))
+              (throw 'found t))))))
+
 (defun eshell-gather-process-output (command args)
   "Gather the output from COMMAND + ARGS."
   (unless (and (file-executable-p command)
-              (file-regular-p command))
+              (file-regular-p (file-truename command)))
     (error "%s: not an executable file" command))
   (let* ((delete-exited-processes
          (if eshell-current-subjob-p
@@ -250,13 +270,16 @@ Used only on systems which do not support async subprocesses.")
         (process-environment (eshell-environment-variables))
         proc decoding encoding changed)
     (cond
-     ((fboundp 'start-process)
+     ((fboundp 'start-file-process)
       (setq proc
-           (apply 'start-process
-                  (file-name-nondirectory command) nil
-                  ;; `start-process' can't deal with relative
-                  ;; filenames
-                  (append (list (expand-file-name command)) args)))
+           (let ((process-connection-type
+                  (unless (eshell-needs-pipe-p command)
+                    process-connection-type))
+                 (command (or (file-remote-p command 'localname) command)))
+             (apply 'start-file-process
+                    (file-name-nondirectory command) nil
+                    ;; `start-process' can't deal with relative filenames.
+                    (append (list (expand-file-name command)) args))))
       (eshell-record-process-object proc)
       (set-process-buffer proc (current-buffer))
       (if (eshell-interactive-output-p)
@@ -504,7 +527,5 @@ See the variable `eshell-kill-processes-on-exit'."
   (eshell-send-input nil nil t)
   (eshell-process-interact 'process-send-eof))
 
-;;; Code:
-
-;;; arch-tag: ac477a3e-ee4d-4b44-8ec6-212010e607bb
+;; arch-tag: ac477a3e-ee4d-4b44-8ec6-212010e607bb
 ;;; esh-proc.el ends here