all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: emacs-devel@gnu.org
Cc: tino.calancha@gmail.com
Subject: Re: [PATCH] Add facility to collect stderr of async subprocess
Date: Wed, 05 Oct 2016 13:33:17 +0900	[thread overview]
Message-ID: <87wphnwh2q.fsf@gmail.com> (raw)
In-Reply-To: <877ftja89d.fsf-ueno@gnu.org> (Daiki Ueno's message of "Sat, 11 Apr 2015 08:11:42 +0900")

Daiki Ueno <ueno@gnu.org> writes:

> Daiki Ueno <ueno@gnu.org> writes:
> I've pushed it to master.

How about to allow direct standard-error output to a different buffer
in start-process as well?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From 087970e4952476d94c43927ed96b1b960fc316fc Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Wed, 5 Oct 2016 11:59:25 +0900
Subject: [PATCH] start-process: Allow separate standard-error from
 standard-output

* lisp/subr.el (start-process): Allow buffer being a cons
(STDOUT-BUFFER . STDERR-BUFFER); the car is the buffer-or-name
for the standard outout, the cdr is the buffer-or-name for the
standard error.
Update doc string.
* lisp/simple.el (async-shell-command):
Use start-process-shell-command instead of start-process.
If error-buffer is non-nil, then write standard-error output there.
* etc/TODO (Other features we would like): Drop this task from TODO list.
* doc/lispref/processes.texi (Asynchronous Processes, Output from Processes):
Update manual.
; * etc/NEWS (Lisp Changes in Emacs 26.1): Add news entry.
---
 doc/lispref/processes.texi | 17 ++++++++++++++---
 etc/NEWS                   |  3 +++
 etc/TODO                   |  3 ---
 lisp/simple.el             | 10 +++++++---
 lisp/subr.el               | 20 ++++++++++----------
 5 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index 87c0b5c..4fbdf47 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -745,7 +745,11 @@ Asynchronous Processes
 for the new subprocess in Lisp.  The argument @var{name} specifies the
 name for the process object; as with @code{make-process}, it is
 modified if necessary to make it unique.  The buffer
-@var{buffer-or-name} is the buffer to associate with the process.
+@var{buffer-or-name} is the buffer to associate with the process.  It
+might be a cons @w{@code{(@var{stdout-buffer} . @var{stderr-buffer})}}
+as well; in this case @var{stdout-buffer} is the buffer to associate with
+the standard output of the process, and @var{stderr-buffer} is the buffer
+to associate with its error output.
 
 If @var{program} is @code{nil}, Emacs opens a new pseudoterminal (pty)
 and associates its input and output with @var{buffer-or-name}, without
@@ -1359,8 +1363,15 @@ Output from Processes
 Emacs uses a pseudo-TTY (pty) for communication with the subprocess,
 then it is impossible to separate the standard output and standard
 error streams of the subprocess, because a pseudo-TTY has only one
-output channel.  In that case, if you want to keep the output to those
-streams separate, you should redirect one of them to a file---for
+output channel.  In case you want to keep the output to those
+streams separate, you should provide also a buffer for the standard
+error.  Then Emacs doesn't use a pseudo-TTY for communication with
+the subprocess.  The way to do that is to start the subprocess with
+the argument @var{buffer-or-name} being a cons
+@w{@code{(@var{stdout-buffer} . @var{stderr-buffer})}}; in that case,
+the subprocess writes its standard output in @var{stdout-buffer} and
+writes its error output in @var{stderr-buffer}.
+Another way could be redirect one of them to a file---for
 example, by using an appropriate shell command via
 @code{start-process-shell-command} or a similar function.
 
diff --git a/etc/NEWS b/etc/NEWS
index bd94c94..a60d859 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -499,6 +499,9 @@ function 'check-declare-errmsg' has been removed.
 \f
 * Lisp Changes in Emacs 26.1
 
+** Now 'start-process' can direct standard-error output to a different
+buffer.
+
 ** New function undo-amalgamate-change-group to get rid of undo-boundaries
 between two states.
 
diff --git a/etc/TODO b/etc/TODO
index fe0e2ac..6749afd 100644
--- a/etc/TODO
+++ b/etc/TODO
@@ -489,9 +489,6 @@ from the emacsclient process.
   immediately, then replace it later.  So that C-s a with
   input method latin-1-postfix would immediately search for an a.
 
-** Give start-process the ability to direct standard-error
-  output to a different filter.
-
 ** Give desktop.el a feature to switch between different named desktops.
 
 ** Add a cpio mode, more or less like tar mode.
diff --git a/lisp/simple.el b/lisp/simple.el
index 70bd759..4c734f2 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3480,9 +3480,13 @@ shell-command
 		  (display-buffer buffer '(nil (allow-no-window . t)))
                   (shell-command--save-pos-or-erase)
 		  (setq default-directory directory)
-		  (setq proc (start-process "Shell" buffer shell-file-name
-					    shell-command-switch command))
-		  (setq mode-line-process '(":%s"))
+		  (setq proc (start-process-shell-command
+                              "Shell"
+                              (if error-buffer
+                                  `(,buffer . ,error-buffer)
+                                buffer)
+                              command)
+                        mode-line-process '(":%s"))
 		  (require 'shell) (shell-mode)
 		  (set-process-sentinel proc 'shell-command-sentinel)
 		  ;; Use the comint filter for proper handling of carriage motion
diff --git a/lisp/subr.el b/lisp/subr.el
index b143812..03b902e 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1989,24 +1989,24 @@ start-process
 NAME is name for process.  It is modified if necessary to make it unique.
 BUFFER is the buffer (or buffer name) to associate with the process.
 
-Process output (both standard output and standard error streams) goes
+If buffer is a cons (STDOUT-BUFFER . STDERR-BUFFER), then the standard
+output and the standard error appear in different buffers.  Otherwise,
+process output (both standard output and standard error streams) goes
 at end of BUFFER, unless you specify an output stream or filter
 function to handle the output.  BUFFER may also be nil, meaning that
 this process is not associated with any buffer.
 
 PROGRAM is the program file name.  It is searched for in `exec-path'
 \(which see).  If nil, just associate a pty with the buffer.  Remaining
-arguments are strings to give program as arguments.
-
-If you want to separate standard output from standard error, use
-`make-process' or invoke the command through a shell and redirect
-one of them using the shell syntax."
+arguments are strings to give program as arguments."
   (unless (fboundp 'make-process)
     (error "Emacs was compiled without subprocess support"))
-  (apply #'make-process
-	 (append (list :name name :buffer buffer)
-		 (if program
-		     (list :command (cons program program-args))))))
+  (apply #'make-process :name name
+         (append (if (consp buffer)
+                     (list :buffer (car buffer) :stderr (cdr buffer))
+                   (list :buffer buffer))
+                 (if program
+                     (list :command (cons program program-args))))))
 
 (defun process-lines (program &rest args)
   "Execute PROGRAM with ARGS, returning its output as a list of lines.
-- 
2.9.3

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.0)
 of 2016-10-04 built on calancha-pc
Repository revision: 13ba5af7427bdbd022a9d449dc2987d6a96591eb



  parent reply	other threads:[~2016-10-05  4:33 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-13  9:01 pipe Daiki Ueno
2015-03-13 10:59 ` pipe Eli Zaretskii
2015-03-13 12:29   ` pipe Daiki Ueno
2015-03-13 20:08     ` pipe Werner Koch
2015-03-14  8:54       ` pipe Eli Zaretskii
2015-03-14 11:51         ` pipe Werner Koch
2015-03-14 13:42           ` pipe Eli Zaretskii
2015-03-14 19:28             ` pipe Werner Koch
2015-03-14 20:34               ` pipe Eli Zaretskii
2015-03-17  7:22                 ` pipe Daiki Ueno
2015-03-17  8:47                   ` pipe Eli Zaretskii
2015-03-13 12:45 ` pipe Stefan Monnier
2015-03-13 13:10   ` pipe Daiki Ueno
2015-03-16  5:42     ` [PATCH] Generalize start-process with keyword args Daiki Ueno
2015-03-16 13:34       ` Stefan Monnier
2015-03-17  2:16         ` Daiki Ueno
2015-03-17  3:13           ` Stefan Monnier
2015-03-17  3:39             ` Daiki Ueno
2015-03-17 15:35               ` Stefan Monnier
2015-03-17 15:42                 ` Eli Zaretskii
2015-03-17 18:08                   ` Stefan Monnier
2015-03-17 18:19                     ` Eli Zaretskii
2015-03-17 21:36                       ` Stefan Monnier
2015-03-18  3:47                         ` Eli Zaretskii
2015-03-18  6:17                           ` Daiki Ueno
2015-03-18  7:37                             ` [PATCH] Add facility to collect stderr of async subprocess Daiki Ueno
2015-03-18 16:25                               ` Eli Zaretskii
2015-03-31  7:27                                 ` Daiki Ueno
2015-03-31 12:55                                   ` Eli Zaretskii
2015-04-08  0:21                                     ` Daiki Ueno
2015-04-08  0:47                                       ` Paul Eggert
2015-04-08  2:55                                         ` Daiki Ueno
2015-04-08  6:17                                           ` Eli Zaretskii
2015-04-08  6:20                                             ` Eli Zaretskii
2015-04-08  7:05                                             ` Daiki Ueno
2015-04-10 23:11                                               ` Daiki Ueno
2015-04-18 10:55                                                 ` Ted Zlatanov
2016-10-05  4:33                                                 ` Tino Calancha [this message]
2016-10-05  6:54                                                   ` Eli Zaretskii
2016-10-05  7:10                                                     ` Tino Calancha
2016-10-05  7:37                                                       ` Eli Zaretskii
2016-10-05 16:22                                                         ` John Wiegley
2016-10-06  3:13                                                           ` Tino Calancha
2016-10-06  6:54                                                             ` Eli Zaretskii
2016-10-06  7:25                                                               ` Tino Calancha
2016-10-06  7:55                                                                 ` Eli Zaretskii
2016-10-06  8:37                                                                   ` Tino Calancha
2016-10-06  8:53                                                                     ` Eli Zaretskii
2016-10-06  9:13                                                                       ` Tino Calancha
2016-10-06  9:25                                                                         ` Michael Albinus
2016-10-06  9:45                                                                           ` Tino Calancha
2016-10-06  9:22                                                                     ` Michael Albinus
2016-10-06  7:15                                                         ` Philipp Stephani
2016-10-06  7:42                                                           ` Eli Zaretskii
2016-10-05  8:46                                                     ` Alain Schneble
2016-10-05  9:15                                                       ` Tino Calancha
2016-10-05 11:20                                                     ` Michael Albinus
2016-10-05 17:24                                                       ` Eli Zaretskii
2016-10-06  7:27                                                         ` Michael Albinus
2015-04-08  5:56                                       ` Eli Zaretskii
2015-03-18 13:03                             ` [PATCH] Generalize start-process with keyword args Stefan Monnier
2015-03-18 16:34                               ` Eli Zaretskii
2015-03-19  7:36                               ` Daiki Ueno
2015-03-19 13:32                                 ` Stefan Monnier
2015-03-23  7:36                                   ` Daiki Ueno
2015-03-18 16:23                             ` Eli Zaretskii
2015-03-18 18:57                               ` Stefan Monnier
2015-03-18 19:13                                 ` Eli Zaretskii
2015-03-17  7:50           ` Eli Zaretskii
2015-03-16 19:12       ` Andy Moreton
2015-03-16 19:40         ` Eli Zaretskii
2015-03-16 22:27           ` Andy Moreton
2015-03-17  0:39             ` Stefan Monnier
2015-03-17  7:15             ` Eli Zaretskii
2015-03-17 20:55               ` Andy Moreton
2015-03-17 21:15                 ` Eli Zaretskii
2015-03-17 22:04                   ` Andy Moreton
2015-03-19 16:34                     ` Eli Zaretskii
2015-03-19 23:22                       ` Andy Moreton
2015-03-20 14:03                         ` Stefan Monnier
2015-03-17 21:42                 ` Stefan Monnier
2015-03-13 14:54   ` pipe Eli Zaretskii
2015-03-13 15:28     ` pipe Daniel Colascione
2015-03-13 15:40       ` pipe Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wphnwh2q.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.