unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Confused about sending text to a subprocess
@ 2010-04-03  0:29 Sean McAfee
  2010-04-03  3:09 ` Harald Hanche-Olsen
  0 siblings, 1 reply; 3+ messages in thread
From: Sean McAfee @ 2010-04-03  0:29 UTC (permalink / raw)
  To: help-gnu-emacs

So I have this little Perl script:

  #!/usr/bin/perl
  open X, ">/home/me/ABCXYZ" or die "$!\n";
  print X "Start ", scalar localtime, "\n";
  print X $_ while <STDIN>;
  print X "\nEnd\n";

I invoke it from Emacs like this:

  (let ((proc (start-process "x" nil "/path/to/perl/script")))
    (process-send-string proc "foo\n")
    (process-send-eof proc))

It works as I expect.  But if I leave off that newline:

    (process-send-string proc "foo")

...then the subprocess does not exit.  It continues to appear in the
list returned by process-list, and its status, as reported by
process-status, is "run".  No output appears in that Perl script's
output file, I suppose because it's being buffered and the script is
still stuck in that loop on STDIN.

In most languages I might write something like this in, I would indicate
an end to the output to the subprocess by simply calling close() on a
stream that's connected to the subprocess's pipe.  I had supposed that
that's what Emacs's process-send-eof does, but I don't think that can be
correct.  Actually, the section of the Emacs Lisp manual entitled
"Sending Input to Processes" is rather confusing in this regard; it
states:

>Some operating systems have limited space for buffered input in a
>PTY. On these systems, Emacs sends an EOF periodically amidst the other
>characters, to force them through. For most programs, these EOFs do no
>harm.

I don't even know what it means to send an EOF amidst other characters.
I thought EOF was the special out-of-band code (usually -1) that
getchar(3) et al. return to indicate that a stream has been closed.

Maybe I'm missing something obvious, but I've looked all over the
"Processes" section of the manual, and I haven't found any function that
says it simply closes the connection to the subprocess.  There are
several that send signals to the subprocess, but I don't want to do
that.

What's the right way to indicate that one is totally finished sending
data to a subprocess, and that the connection should be completely
closed?


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

end of thread, other threads:[~2010-04-03  8:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-03  0:29 Confused about sending text to a subprocess Sean McAfee
2010-04-03  3:09 ` Harald Hanche-Olsen
2010-04-03  8:47   ` Sean McAfee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).