all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* reading from standard input in batch mode
@ 2018-05-22 20:16 Eric Abrahamsen
  2018-05-22 20:44 ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2018-05-22 20:16 UTC (permalink / raw
  To: help-gnu-emacs

I'm trying to figure out how batch mode works, and I want to do
something very simple: call a subordinate emacs process, passing it a
string, and have it write the string to a file. It's not working but I
don't know how to debug this.

In boomerang.el:

(defun boomerang ()
  (let ((msg (read)))
    (append-to-file msg
		    nil
		    "/home/eric/tmp/results.txt")))

In my main emacs:

(shell-command
"emacs -Q --batch -l boomerang.el -f boomerang \"hi there\"")

The subordinate emacs starts and finishes (returning 255, which just
came up on a thread in emacs.devel, I think), but no file is written. As
far as I know, `read' should be reading from standard-input in this
case. What am I doing wrong?

Thanks,
Eric




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: reading from standard input in batch mode
  2018-05-22 20:16 reading from standard input in batch mode Eric Abrahamsen
@ 2018-05-22 20:44 ` Eric Abrahamsen
  2018-05-22 20:49   ` Eric Abrahamsen
  2018-05-22 20:50   ` Noam Postavsky
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2018-05-22 20:44 UTC (permalink / raw
  To: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> I'm trying to figure out how batch mode works, and I want to do
> something very simple: call a subordinate emacs process, passing it a
> string, and have it write the string to a file. It's not working but I
> don't know how to debug this.
>
> In boomerang.el:
>
> (defun boomerang ()
>   (let ((msg (read)))
>     (append-to-file msg
> 		    nil
> 		    "/home/eric/tmp/results.txt")))
>
> In my main emacs:
>
> (shell-command
> "emacs -Q --batch -l boomerang.el -f boomerang \"hi there\"")
>
> The subordinate emacs starts and finishes (returning 255, which just
> came up on a thread in emacs.devel, I think), but no file is written. As
> far as I know, `read' should be reading from standard-input in this
> case. What am I doing wrong?

I figured it out, it should have been (read t). Ignore me!




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: reading from standard input in batch mode
  2018-05-22 20:44 ` Eric Abrahamsen
@ 2018-05-22 20:49   ` Eric Abrahamsen
  2018-05-22 20:50   ` Noam Postavsky
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2018-05-22 20:49 UTC (permalink / raw
  To: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> I'm trying to figure out how batch mode works, and I want to do
>> something very simple: call a subordinate emacs process, passing it a
>> string, and have it write the string to a file. It's not working but I
>> don't know how to debug this.
>>
>> In boomerang.el:
>>
>> (defun boomerang ()
>>   (let ((msg (read)))
>>     (append-to-file msg
>> 		    nil
>> 		    "/home/eric/tmp/results.txt")))
>>
>> In my main emacs:
>>
>> (shell-command
>> "emacs -Q --batch -l boomerang.el -f boomerang \"hi there\"")
>>
>> The subordinate emacs starts and finishes (returning 255, which just
>> came up on a thread in emacs.devel, I think), but no file is written. As
>> far as I know, `read' should be reading from standard-input in this
>> case. What am I doing wrong?
>
> I figured it out, it should have been (read t). Ignore me!

No, dangit, it still doesn't work. I changed the (read) to (read t), and
changed the invocation to:

(shell-command
 "emacs -Q --batch -l boomerang.el -f boomerang \"hi there\"" "*output*"
 "*error*")

And *output* contains "Lisp expression:" (ie, it's still trying to read
from the minibuffer), and *error* contains "Error reading from stdin",
(ie, it couldn't read from the minibuffer).

Am I passing the string in incorrectly?




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: reading from standard input in batch mode
  2018-05-22 20:44 ` Eric Abrahamsen
  2018-05-22 20:49   ` Eric Abrahamsen
@ 2018-05-22 20:50   ` Noam Postavsky
  2018-05-22 21:07     ` Eric Abrahamsen
  1 sibling, 1 reply; 8+ messages in thread
From: Noam Postavsky @ 2018-05-22 20:50 UTC (permalink / raw
  To: Eric Abrahamsen; +Cc: Help Gnu Emacs mailing list

On 22 May 2018 at 16:44, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

>> (shell-command
>> "emacs -Q --batch -l boomerang.el -f boomerang \"hi there\"")
>>
>> The subordinate emacs starts and finishes (returning 255, which just
>> came up on a thread in emacs.devel, I think), but no file is written. As
>> far as I know, `read' should be reading from standard-input in this
>> case. What am I doing wrong?
>
> I figured it out, it should have been (read t). Ignore me!

Shouldn't it have been:

(shell-command
  "echo \"hi there\" | emacs -Q --batch -l boomerang.el -f boomerang")



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: reading from standard input in batch mode
  2018-05-22 20:50   ` Noam Postavsky
@ 2018-05-22 21:07     ` Eric Abrahamsen
  2018-05-22 21:18       ` Eric Abrahamsen
  2018-05-22 21:26       ` Noam Postavsky
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2018-05-22 21:07 UTC (permalink / raw
  To: help-gnu-emacs

Noam Postavsky <npostavs@gmail.com> writes:

> On 22 May 2018 at 16:44, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>
>>> (shell-command
>>> "emacs -Q --batch -l boomerang.el -f boomerang \"hi there\"")
>>>
>>> The subordinate emacs starts and finishes (returning 255, which just
>>> came up on a thread in emacs.devel, I think), but no file is written. As
>>> far as I know, `read' should be reading from standard-input in this
>>> case. What am I doing wrong?
>>
>> I figured it out, it should have been (read t). Ignore me!
>
> Shouldn't it have been:
>
> (shell-command
>   "echo \"hi there\" | emacs -Q --batch -l boomerang.el -f boomerang")

Of course -- I don't know why I thought passing a string as an argument
would work.

Turns out I needed:

$ echo "\"hi there\""

So that the string was a string, but that was easy to figure out. The
output unfortunately also contains the string "Lisp expression:" but I
can probably figure that out, too.

Thanks!
Eric




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: reading from standard input in batch mode
  2018-05-22 21:07     ` Eric Abrahamsen
@ 2018-05-22 21:18       ` Eric Abrahamsen
  2018-05-22 21:26       ` Noam Postavsky
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2018-05-22 21:18 UTC (permalink / raw
  To: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> The output unfortunately also contains the string "Lisp expression:"
> but I can probably figure that out, too.

Yet this function does just what I want, with no "Lisp expression:" in
it, so I'm done!

(defun boomerang ()
  (append-to-file (read t) nil "/home/eric/tmp/results.txt"))





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: reading from standard input in batch mode
  2018-05-22 21:07     ` Eric Abrahamsen
  2018-05-22 21:18       ` Eric Abrahamsen
@ 2018-05-22 21:26       ` Noam Postavsky
  2018-05-22 21:52         ` Eric Abrahamsen
  1 sibling, 1 reply; 8+ messages in thread
From: Noam Postavsky @ 2018-05-22 21:26 UTC (permalink / raw
  To: Eric Abrahamsen; +Cc: Help Gnu Emacs mailing list

On 22 May 2018 at 17:07, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> output unfortunately also contains the string "Lisp expression:"

Might have to do with the FIXME in lread.c:

DEFUN ("read", Fread, Sread, 0, 1, 0,
       doc: [...])
  (Lisp_Object stream)
{
  if (NILP (stream))
    stream = Vstandard_input;
  if (EQ (stream, Qt))
    stream = Qread_char;
  if (EQ (stream, Qread_char))
    /* FIXME: ?! When is this used !?  */
    return call1 (intern ("read-minibuffer"),
          build_string ("Lisp expression: "));

  return read_internal_start (stream, Qnil, Qnil);
}



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: reading from standard input in batch mode
  2018-05-22 21:26       ` Noam Postavsky
@ 2018-05-22 21:52         ` Eric Abrahamsen
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2018-05-22 21:52 UTC (permalink / raw
  To: help-gnu-emacs

Noam Postavsky <npostavs@gmail.com> writes:

> On 22 May 2018 at 17:07, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>
>> output unfortunately also contains the string "Lisp expression:"
>
> Might have to do with the FIXME in lread.c:
>
> DEFUN ("read", Fread, Sread, 0, 1, 0,
>        doc: [...])
>   (Lisp_Object stream)
> {
>   if (NILP (stream))
>     stream = Vstandard_input;
>   if (EQ (stream, Qt))
>     stream = Qread_char;
>   if (EQ (stream, Qread_char))
>     /* FIXME: ?! When is this used !?  */
>     return call1 (intern ("read-minibuffer"),
>           build_string ("Lisp expression: "));
>
>   return read_internal_start (stream, Qnil, Qnil);
> }

Beats me, really -- I guess it's trying to figure out when you're using
it interactively, and when you aren't? `princ' and `prin1' gave me the
prepended string, but `append-to-file' on the string didn't.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-05-22 21:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-22 20:16 reading from standard input in batch mode Eric Abrahamsen
2018-05-22 20:44 ` Eric Abrahamsen
2018-05-22 20:49   ` Eric Abrahamsen
2018-05-22 20:50   ` Noam Postavsky
2018-05-22 21:07     ` Eric Abrahamsen
2018-05-22 21:18       ` Eric Abrahamsen
2018-05-22 21:26       ` Noam Postavsky
2018-05-22 21:52         ` Eric Abrahamsen

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.