bugGNU Octave - Bugs: bug #49864, fscanf incomplete read with popen...

 
 

bug #49864: fscanf incomplete read with popen (Windows)

Submitter:  Denis Sbragion <dsbragion>
Submitted:  Fri 16 Dec 2016 02:37:27 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  fscanf, popen Open/Closed:  * Closed
Release:  * 4.2.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 21 May 2020 03:54:19 PM UTC, comment #2: 

I can reproduce this issue with Octave 4.2.2 and 4.4.1.
It works correctly in version 5.0.1 and newer. So it looks like this has been fixed somewhere along the way.

Closing as fixed.

Markus Mützel <mmuetzel>
Group administrator
Fri 16 Dec 2016 09:25:48 PM UTC, comment #1: 

popen() just doesn't work very well on Windows.  I tried the following:


fid = popen ("type testfile.txt", "r");
[a,b,c] = fscanf (fid, "%f,%f", 2)


I tried reading each line at a time and I get wild results.  Instead of the numbers 1234 and 5678, I get truncations such as "34,8" and "5678,1".

I've marked this as a regression since according to your tests it worked in 4.0.3, but I don't know what is going on here.

Rik <rik5>
Group administrator
Fri 16 Dec 2016 02:37:27 PM UTC, original submission:  

Hello,

the attacched script and test file could be used to reproduce the bug. The script simply performs the same file read both through a standard file and a popen pipe:


pp = fopen('testfile.txt','rt');
size(fscanf(pp,'%f;%f'))
fclose(pp);

pp = popen('type testfile.txt','r');
size(fscanf(pp,'%f;%f'))
pclose(pp);


The two sections of the script of course should provide the same output. "testfile.txt" is just a sequence of comma separated numbers, nothing special.

With Octave 4.0.3 the result is correct:


octave:7> fscanfbug
ans =

   3240      1

ans =

   3240      1


With Octave 4.2.0 I get the following output:


octave:4> fscanfbug
Il processo ha tentato di scrivere in una pipe non esistente.
ans =

   3240      1

ans =

   4   1


The error message at the top translated means "The process tried to write to a non existant pipe".

It looks like fscanf stops reading before the "type" command finishes to write its output, so the following pclose closes the pipe and then the error.

Thanks in advance for your attention.

Bye,

Denis Sbragion

Denis Sbragion <dsbragion>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #39251:  fscanfbug.m added by dsbragion (144B - text/x-objcsrc - Test script and sample input file)
file #39252:  testfile.txt added by dsbragion (17KiB - text/plain - Test script and sample input file)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by dsbragion (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-05-21 mmuetzel StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2016-12-16 rik5 Item GroupIncorrect Result Regression
        StatusNone Confirmed
        Summaryfscanf incomplete read with popen fscanf incomplete read with popen (Windows)
    2016-12-16 dsbragion Attached File- Added fscanfbug.m, #39251
        Attached File- Added testfile.txt, #39252

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code