From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Add facility to collect stderr of async subprocess Date: Wed, 05 Oct 2016 13:33:17 +0900 Message-ID: <87wphnwh2q.fsf@gmail.com> References: <83pp87y6iu.fsf@gnu.org> <83mw3bxz9f.fsf@gnu.org> <83k2yfx8zi.fsf@gnu.org> <83egomxog1.fsf@gnu.org> <83ego5tjgt.fsf@gnu.org> <877ftno4fr.fsf-ueno@gnu.org> <55247A98.5020302@cs.ucla.edu> <83r3rvgn4e.fsf@gnu.org> <877ftja89d.fsf-ueno@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1475642058 26078 195.159.176.226 (5 Oct 2016 04:34:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 5 Oct 2016 04:34:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cc: tino.calancha@gmail.com To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 05 06:34:14 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brdu6-0004lm-3y for ged-emacs-devel@m.gmane.org; Wed, 05 Oct 2016 06:34:02 +0200 Original-Received: from localhost ([::1]:46423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brdu4-0001y5-DU for ged-emacs-devel@m.gmane.org; Wed, 05 Oct 2016 00:34:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brdtY-0001xv-3g for emacs-devel@gnu.org; Wed, 05 Oct 2016 00:33:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brdtS-0002Ko-Ii for emacs-devel@gnu.org; Wed, 05 Oct 2016 00:33:27 -0400 Original-Received: from mail-pa0-x243.google.com ([2607:f8b0:400e:c03::243]:36766) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brdtS-0002Kb-3k for emacs-devel@gnu.org; Wed, 05 Oct 2016 00:33:22 -0400 Original-Received: by mail-pa0-x243.google.com with SMTP id cd13so8886807pac.3 for ; Tue, 04 Oct 2016 21:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:cc:date:in-reply-to:message-id :user-agent:mime-version; bh=+b6fMIpqBkfGbMGYiWbgEIjsaO6lu35fg3oEy4qV1mg=; b=kdMxuPLQdPTMgqX+a4Oei2Eg5W4kgmtlbNB2MNQW2bWBnk8hLUStpke9IP0Q1TW70B /mtdN2VAjEs+VxFtzkRdzV93P0W1jRH5QY+tPNuvsLkNA4wD9UKH+T6hdyCSuL90tF4W kMfgW/NQA6TGoMaX2W5HZ+/hoW1mrfpmre9bBRJkOklYdjjFp4JmEgt9dud0XVUMhAB1 Bmtwm0SrFJyzMOwPWbYtcIey2zWmXBvZGJcXhNHQ26TGUGgooEcJVsTh+WqA+A3xCjf7 If9B1YTKUmM9wsYdKGR1pbkeeHX7htLitZNn8lcYZ/kiAoDwgMyHpoSy/bTcULRI36TR EjWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:references:cc:date:in-reply-to :message-id:user-agent:mime-version; bh=+b6fMIpqBkfGbMGYiWbgEIjsaO6lu35fg3oEy4qV1mg=; b=aYD9UHBIIKnep84B2jtiYVdsvxiQfnlZDsWrbCdkGovCe+kTOQHxE0GQP80H7eK4Pu tBxl8Ho7ie/iB3tSt+aM1r+nKuNh3XWnFOkBPsENbU13z0bGZvD4QG1S0a0rZxEhNK6U 2rwt8gL7Cegig+nyc+iWBt7grC0TqlCO9cG0xCumM1w7lT1a8djyUAM8CrPpong4vCD3 VptUVTTkslFdDLWgkEjyj7PZPeg+1U9cjOtJl8emLnix3EZrPMAfJj67hIDMTkwe6IS8 qD1r9vwABZ/YP/S31VQq94iW95dmKCEFnuhiCkFiZFmsoEJSPwFOUv3YnyKFU6jBVUMf rJZg== X-Gm-Message-State: AA6/9Rly9wVIMnVe1hVQzmYBPkJ+0WjQfV1UZKdRbSJ25z+M2UeH3YSHWvr5XZTTfbnglw== X-Received: by 10.67.15.1 with SMTP id fk1mr5453462pad.127.1475642000793; Tue, 04 Oct 2016 21:33:20 -0700 (PDT) Original-Received: from calancha-pc (57.92.100.220.dy.bbexcite.jp. [220.100.92.57]) by smtp.gmail.com with ESMTPSA id ta7sm1460718pac.48.2016.10.04.21.33.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Oct 2016 21:33:20 -0700 (PDT) In-Reply-To: <877ftja89d.fsf-ueno@gnu.org> (Daiki Ueno's message of "Sat, 11 Apr 2015 08:11:42 +0900") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207988 Archived-At: Daiki Ueno writes: > Daiki Ueno 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 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. * 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