From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mathias Dahl Newsgroups: gmane.emacs.devel Subject: kill-emacs and returning values Date: Sat, 14 Feb 2009 14:51:16 +0100 Message-ID: <7dbe73ed0902140551w7a85d043n54e451896d99279e@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1234619500 2283 80.91.229.12 (14 Feb 2009 13:51:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 14 Feb 2009 13:51:40 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 14 14:52:56 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LYKwr-0005Fr-RO for ged-emacs-devel@m.gmane.org; Sat, 14 Feb 2009 14:52:50 +0100 Original-Received: from localhost ([127.0.0.1]:32778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LYKvX-0002r5-Ni for ged-emacs-devel@m.gmane.org; Sat, 14 Feb 2009 08:51:27 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LYKvR-0002qg-LA for emacs-devel@gnu.org; Sat, 14 Feb 2009 08:51:21 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LYKvP-0002qU-13 for emacs-devel@gnu.org; Sat, 14 Feb 2009 08:51:20 -0500 Original-Received: from [199.232.76.173] (port=55814 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LYKvO-0002qR-RR for emacs-devel@gnu.org; Sat, 14 Feb 2009 08:51:18 -0500 Original-Received: from fk-out-0910.google.com ([209.85.128.188]:27080) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LYKvO-0006Rr-A7 for emacs-devel@gnu.org; Sat, 14 Feb 2009 08:51:18 -0500 Original-Received: by fk-out-0910.google.com with SMTP id 19so968040fkr.10 for ; Sat, 14 Feb 2009 05:51:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=KJAJDSp5la0PRVi9W6NlGlyPwuawWVvaaeHC8Z2Frhc=; b=n8GHGIMUoFElGHuF8jJxqpLMR+wAZgx2umYFI8yOYG92LrX2tJ6ud18u6oJMCjgfbx rZnXIwOaPnZRCk8lkOquduqUj6yVc/rKCT35uYrbj3pmUswaDu8mWJpTZu0F1cz82Vwm PO+giDj0QbkMR1TPObmapWJJwPXYJvWxcfFTE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=WXoksgOWJFcpUzr2sk/cQIApu+zmvsdgMT9eWv3hxO5EjAfFkJc2E75BOZ8pPb/wyJ jDvlXk6FH+YsRuhVNZe94Z1BVlnq+5VL2J29qW97+RrGIgB/U6zkRlxeldhdqhTTte0o eUttbduJlzGuCEDMPNe0Np+Ph9xpmaio0Yyc8= Original-Received: by 10.103.131.18 with SMTP id i18mr351938mun.120.1234619476443; Sat, 14 Feb 2009 05:51:16 -0800 (PST) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:109063 Archived-At: I am trying to use emacs interactively as part of a shell script and want to return a value that I can use in the script. How is the optional string parameter to `kill-emacs' supposed to be used? The docstring says: === kill-emacs is an interactive built-in function in `C source code'. (kill-emacs &optional arg) Exit the Emacs job and kill it. If arg is an integer, return arg as the exit program code. If arg is a string, stuff it as keyboard input. === Okay, sounds promising. I did a small test: $ cat ke.el ;; Interactive stuff goes here... ;; In the end, kill emacs and return a value to the script running in ;; the shell (kill-emacs "This is the return value.") Testing it: $ emacs -Q -nw -l ke.el This is the return value. So far so good. Now I want to save this value in a variable. mathias@klibb:~$ emacs -Q -nw -l ke.el; read returnvariable This is the return value. Let's see what we got: mathias@klibb:~$ echo $returnvariable $ Nothing? Okay... A pipe must be used, of course, Next try: mathias@klibb:~$ emacs -Q -nw -l ke.el | read returnvariable This is the return value. mathias@klibb:~$ echo $returnvariable $ I see now that "as keyboard input" does not mean what I thought; it is not something returned to stdout. How is this supposed to be used? It would seem more natural to return things to stdout, but I am sure there is a good reason for it to work the way it does, it's just that I don't understand it. Please note that I do not want to use emacs in batch mode. Emacs must be responsive because I am building a UI for file selection in it. Thanks! /Mathias PS. Of course I can use write-region and write what I want to a file and then read the result from there, but that seems like a less elegant solution to me.