[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Confused about sending text to a subprocess
From: |
Sean McAfee |
Subject: |
Confused about sending text to a subprocess |
Date: |
Tue, 04 May 2010 15:43:58 -0000 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) |
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?
- Confused about sending text to a subprocess,
Sean McAfee <=