* How to flush output to process
@ 2011-11-06 9:53 Frank Fischer
2011-11-06 11:07 ` Eli Zaretskii
0 siblings, 1 reply; 10+ messages in thread
From: Frank Fischer @ 2011-11-06 9:53 UTC (permalink / raw
To: help-gnu-emacs
Hi,
I have a question about communication with processes. I want to start
an external program from Emacs Lisp in a process (using
`start-file-process'). This program accepts input data from stdin and
writes its results to stdout. After sending data to the process using
`process-send-string' nothing happens if the data does not end in a
newline character. The problem is that in general I cannot end every
request I send to the process with a newline (a constraint of the
communication protocol) and using `process-send-eof' is also not an
option because this seems to close the connection completely (I want
to communicate with the process in several turns).
In something like C I would use fflush(...) to force the buffered data
to be sent to the process (and it works), but I have not been able to
find some comparable function for Emacs Lisp.
Is there a way the flush the Emacs->process stream, i.e., force all
buffered data to be actually send to the process, from Emacs Lisp?
Thanks in advance,
Frank
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-06 9:53 How to flush output to process Frank Fischer
@ 2011-11-06 11:07 ` Eli Zaretskii
2011-11-06 11:38 ` Frank Fischer
[not found] ` <mailman.1911.1320579191.15868.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 10+ messages in thread
From: Eli Zaretskii @ 2011-11-06 11:07 UTC (permalink / raw
To: help-gnu-emacs
> From: Frank Fischer <frank-fischer@shadow-soft.de>
> Date: Sun, 6 Nov 2011 09:53:39 +0000 (UTC)
>
> In something like C I would use fflush(...) to force the buffered data
> to be sent to the process (and it works), but I have not been able to
> find some comparable function for Emacs Lisp.
>
> Is there a way the flush the Emacs->process stream, i.e., force all
> buffered data to be actually send to the process, from Emacs Lisp?
I'm guessing that your analysis of the problem (and therefore the
solution you are seeking) is incorrect. I think it's the sub-process
who is buffering input until it sees a newline.
To fix this, make sure your subprocess reads its stdin in raw mode,
not in cooked mode.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-06 11:07 ` Eli Zaretskii
@ 2011-11-06 11:38 ` Frank Fischer
2011-11-06 21:08 ` Thien-Thi Nguyen
[not found] ` <mailman.1911.1320579191.15868.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 10+ messages in thread
From: Frank Fischer @ 2011-11-06 11:38 UTC (permalink / raw
To: help-gnu-emacs
Am Sun, 06 Nov 2011 06:07:17 -0500
schrieb Eli Zaretskii <eliz@gnu.org>:
> > From: Frank Fischer <frank-fischer@shadow-soft.de>
> > Date: Sun, 6 Nov 2011 09:53:39 +0000 (UTC)
> >
> > In something like C I would use fflush(...) to force the buffered
> > data to be sent to the process (and it works), but I have not been
> > able to find some comparable function for Emacs Lisp.
> >
> > Is there a way the flush the Emacs->process stream, i.e., force all
> > buffered data to be actually send to the process, from Emacs Lisp?
>
> I'm guessing that your analysis of the problem (and therefore the
> solution you are seeking) is incorrect. I think it's the sub-process
> who is buffering input until it sees a newline.
>
> To fix this, make sure your subprocess reads its stdin in raw mode,
> not in cooked mode.
Well, I cannot change the subprocess' code. But even if it is a problem
of the subprocess, why does it work if I communicate with the
subprocess from some other program, i.e., not starting the process from
Emacs but from some other programming language, AND call the flush
function of the corresponding stream?
Btw, I would be surprised if it is indeed a problem of the subprocess
as it is designed to be used in this way.
Frank
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
[not found] ` <mailman.1911.1320579191.15868.help-gnu-emacs@gnu.org>
@ 2011-11-06 18:21 ` Helmut Eller
0 siblings, 0 replies; 10+ messages in thread
From: Helmut Eller @ 2011-11-06 18:21 UTC (permalink / raw
To: help-gnu-emacs
* Frank Fischer [2011-11-06 11:38] writes:
> Am Sun, 06 Nov 2011 06:07:17 -0500
> schrieb Eli Zaretskii <eliz@gnu.org>:
>
>> > From: Frank Fischer <frank-fischer@shadow-soft.de>
>> > Date: Sun, 6 Nov 2011 09:53:39 +0000 (UTC)
>> >
>> > In something like C I would use fflush(...) to force the buffered
>> > data to be sent to the process (and it works), but I have not been
>> > able to find some comparable function for Emacs Lisp.
>> >
>> > Is there a way the flush the Emacs->process stream, i.e., force all
>> > buffered data to be actually send to the process, from Emacs Lisp?
>>
>> I'm guessing that your analysis of the problem (and therefore the
>> solution you are seeking) is incorrect. I think it's the sub-process
>> who is buffering input until it sees a newline.
>>
>> To fix this, make sure your subprocess reads its stdin in raw mode,
>> not in cooked mode.
>
> Well, I cannot change the subprocess' code. But even if it is a problem
> of the subprocess, why does it work if I communicate with the
> subprocess from some other program, i.e., not starting the process from
> Emacs but from some other programming language, AND call the flush
> function of the corresponding stream?
process-send-string does no buffering.
> Btw, I would be surprised if it is indeed a problem of the subprocess
> as it is designed to be used in this way.
Maybe it's an end-of-line conversion issue. The subprocess may expect
\r\n on end-of-line. What's the process-coding-system?
Helmut
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-06 11:38 ` Frank Fischer
@ 2011-11-06 21:08 ` Thien-Thi Nguyen
2011-11-06 21:56 ` Frank Fischer
2011-11-09 11:26 ` Frank Fischer
0 siblings, 2 replies; 10+ messages in thread
From: Thien-Thi Nguyen @ 2011-11-06 21:08 UTC (permalink / raw
To: Frank Fischer; +Cc: help-gnu-emacs
() Frank Fischer <frank-fischer@shadow-soft.de>
() Sun, 6 Nov 2011 12:38:20 +0100
Btw, I would be surprised if it is indeed a problem of the
subprocess as it is designed to be used in this way.
If the subprocess is comfortable ignoring signals from Emacs,
you might try using pipes instead of ptys to talk to it.
That would probably eliminate raw/cooked misunderstandings.
See ‘process-connection-type’ (info "(elisp) Asynchronous Processes").
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-06 21:08 ` Thien-Thi Nguyen
@ 2011-11-06 21:56 ` Frank Fischer
2011-11-07 8:49 ` Thien-Thi Nguyen
2011-11-09 11:26 ` Frank Fischer
1 sibling, 1 reply; 10+ messages in thread
From: Frank Fischer @ 2011-11-06 21:56 UTC (permalink / raw
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
Am Sun, 06 Nov 2011 22:08:32 +0100
schrieb Thien-Thi Nguyen <ttn@gnuvola.org>:
> () Frank Fischer <frank-fischer@shadow-soft.de>
> () Sun, 6 Nov 2011 12:38:20 +0100
>
> Btw, I would be surprised if it is indeed a problem of the
> subprocess as it is designed to be used in this way.
>
> If the subprocess is comfortable ignoring signals from Emacs,
> you might try using pipes instead of ptys to talk to it.
> That would probably eliminate raw/cooked misunderstandings.
>
> See ‘process-connection-type’ (info "(elisp) Asynchronous Processes").
I do use pipes, but the problem remains.
Frank
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-06 21:56 ` Frank Fischer
@ 2011-11-07 8:49 ` Thien-Thi Nguyen
2011-11-07 19:29 ` Frank Fischer
0 siblings, 1 reply; 10+ messages in thread
From: Thien-Thi Nguyen @ 2011-11-07 8:49 UTC (permalink / raw
To: Frank Fischer; +Cc: help-gnu-emacs
() Frank Fischer <frank-fischer@shadow-soft.de>
() Sun, 6 Nov 2011 22:56:07 +0100
I do use pipes, but the problem remains.
Perhaps you need to specify the ‘no-conversion’ coding system by frobbing
‘coding-system-for-write’ (info "(elisp) Specifying Coding Systems"), or
something along those lines.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-07 8:49 ` Thien-Thi Nguyen
@ 2011-11-07 19:29 ` Frank Fischer
2011-11-07 19:43 ` Thien-Thi Nguyen
0 siblings, 1 reply; 10+ messages in thread
From: Frank Fischer @ 2011-11-07 19:29 UTC (permalink / raw
To: help-gnu-emacs
Am Mon, 07 Nov 2011 09:49:52 +0100
schrieb Thien-Thi Nguyen <ttn@gnuvola.org>:
> () Frank Fischer <frank-fischer@shadow-soft.de>
> () Sun, 6 Nov 2011 22:56:07 +0100
>
> I do use pipes, but the problem remains.
>
> Perhaps you need to specify the ‘no-conversion’ coding system by
> frobbing ‘coding-system-for-write’ (info "(elisp) Specifying Coding
> Systems"), or something along those lines.
>
I tried it again today and now it work - no idea what I did differently
last time. Thank you for your advices and sorry for bothering.
Frank
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-07 19:29 ` Frank Fischer
@ 2011-11-07 19:43 ` Thien-Thi Nguyen
0 siblings, 0 replies; 10+ messages in thread
From: Thien-Thi Nguyen @ 2011-11-07 19:43 UTC (permalink / raw
To: Frank Fischer; +Cc: help-gnu-emacs
() Frank Fischer <frank-fischer@shadow-soft.de>
() Mon, 7 Nov 2011 20:29:15 +0100
I tried it again today and now it work - no idea what I did differently
last time. Thank you for your advices and sorry for bothering.
I used to run my computer 24x7, with the consequence that Emacs uptime was
many-monthed. Being conscientious, i made sure to sync changes in *scratch*
w/ (what i presumed to be) analogous changes in ~/.emacs. Then one fateful
day, i typed ‘C-x C-c’ by mistake. Hundreds of buffers gone. Bummer.
Moment of truth: time to restart Emacs. You can guess the outcome: errors
(multiple) in ~/.emacs, errors (multiple) in filenames and other linkages,
errors errors everywhere. Major bummer.
So now i know being conscientious is not something to be so proud of. :-D
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to flush output to process
2011-11-06 21:08 ` Thien-Thi Nguyen
2011-11-06 21:56 ` Frank Fischer
@ 2011-11-09 11:26 ` Frank Fischer
1 sibling, 0 replies; 10+ messages in thread
From: Frank Fischer @ 2011-11-09 11:26 UTC (permalink / raw
To: help-gnu-emacs
On 2011-11-06, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
> () Frank Fischer <frank-fischer@shadow-soft.de>
> () Sun, 6 Nov 2011 12:38:20 +0100
>
> Btw, I would be surprised if it is indeed a problem of the
> subprocess as it is designed to be used in this way.
>
> If the subprocess is comfortable ignoring signals from Emacs,
> you might try using pipes instead of ptys to talk to it.
> That would probably eliminate raw/cooked misunderstandings.
>
> See ‘process-connection-type’ (info "(elisp) Asynchronous Processes").
Using pipes seems to work locally. But when starting the process using
tramp a pty has to be used. Any ideas what to do in this case?
Frank
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-11-09 11:26 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-06 9:53 How to flush output to process Frank Fischer
2011-11-06 11:07 ` Eli Zaretskii
2011-11-06 11:38 ` Frank Fischer
2011-11-06 21:08 ` Thien-Thi Nguyen
2011-11-06 21:56 ` Frank Fischer
2011-11-07 8:49 ` Thien-Thi Nguyen
2011-11-07 19:29 ` Frank Fischer
2011-11-07 19:43 ` Thien-Thi Nguyen
2011-11-09 11:26 ` Frank Fischer
[not found] ` <mailman.1911.1320579191.15868.help-gnu-emacs@gnu.org>
2011-11-06 18:21 ` Helmut Eller
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.