Quantcast

octave hangs with fgets (bug?)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

octave hangs with fgets (bug?)

Carnë Draug-2
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
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Loading...