help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strange behavior reading lines from a pipe


From: Mario Storti
Subject: Re: strange behavior reading lines from a pipe
Date: Mon, 8 Jul 2013 10:17:10 -0300

On Mon, Jul 8, 2013 at 4:50 AM, CdeMills <address@hidden> wrote:
> Mario Storti wrote
>> Hi all,
>>
>> I need to synchronize Octave with a C++ program. The program sends to
>> Octave (which is running a script) a double, Octave computes some
>> information, saves to disk, and sends back an OK to the C++ program. The
>> problem I have is that it seems that Octave is one line lagged with
>> respect to what I send.
>
> The problem probably lies deeper. The pipe buffers some data before sending
> them out, in order to reduce awaking the other side very often with small
> data packets. Try opening the pipe, associate a FILE* to it, then use
> setvbuf to put the stream in line-buffered mode. Another approach is to call
> fflush each time you wrote some data to make them immediately available.

In the example I used `cat' to send lines to the Octave script, but in
my C++ program I'm writing to the pipe with `printf' and the file is
set to "line buffering" with

  setvbuf(mypipe,NULL,_IOLBF,0);

And, it doesn't work. As I told in my original post writing to the
pipe with `cat' and reading with Octave `fgetl' has the `1-line-lag'
problem, while reading with the Perl script, or a C++ program with
`getline' works fine. So I guess that the problem is with some kind
of buffering on the Octave reading side.

I didn't tell before, but I tried reading in Octave with fgets and
does have the same problem (1-line-lag).

Regards, and thanks for your help, Mario

-------------------------
Mario Alberto Storti
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colect. Ruta Nac. 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1015), Tel/Fax: +54-342-4511169
Home: +54-342-4550193, e-mail: mario.storti at gmail.com
http://www.cimec.org.ar/mstorti
-------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]