help-octave
[Top][All Lists]
Advanced

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

octave hangs with fgets (bug?)


From: Carnë Draug
Subject: octave hangs with fgets (bug?)
Date: Thu, 31 Mar 2011 15:03:38 +0100

Hi

I've been trying to use popen and fgets to read values from a dialog
window (through zenity) that sends number though the pipe.

If I understood correctly, fgets should return -1 when there's nothing
else to read. However octave hangs.

I'm using the progress bar dialog from zenity with 'print partial'.
Every time progress bar is moved, the new value is sent through the
pipe followed by a newline. But I can never read the last value
selected on the bar though octave, only the one selected before. I
believe that octave can't handle whatever is sent at the end of each
value because when using fgets to read one character at a time it does
read all of them, hanging only when it should read the newline
character. Also, zenity works just fine in bash.

This should replicate my problem:

octave-3.2.4 > fid = popen("zenity --scale --print-partial", "r")
## adjust bar to value 16
## adjust bar to value 24
octave-3.2.4 > fgets(fid)
ans = 16

octave-3.2.4 > fgets(fid)
## octave hangs here
## adjust bar to value 46
ans = 24

octave-3.2.4 > fgets(fid)
## octave hangs here
## press OK on the zenity dialog
ans = 46

This example shows the problem being on the last character of the
value by using fgets to read one character at a time

octave-3.2.4 > fid = popen("zenity --scale --print-partial", "r")
## adjust bar to value 16
octave-3.2.4 > fgets(fid,1)
ans = 1
octave-3.2.4 > fgets(fid,1)
ans = 6
octave-3.2.4 > fgets(fid,1)
## octave hangs here instead of returning -1

This shows that zenity works fine in bash
$ zenity --scale --print-partial
## move bar to 16
16

## move bar to 27
27

## move bar to 54
54

## press ok
54

Is this a bug in octave? Or am I doing it wrong? Thanks in advance for any help
Carnë Draug


reply via email to

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