fread with a pipe and a skip

spasmous spasmous at gmail.com
Wed Mar 11 17:42:24 CDT 2009


I have a code snippet below that reproduces what may be a bug. Basically,
when freading from a pipe and using the skip argument, the pipe is not fully
read in. Results for running the code on my system (3.03) are:

octave:7> mytest
done = 1111 2222 3333 4444 5555 6666
done = 111122223333444455556666
done = 1111 2222 3333 4444 5555 6666
done = 1111
octave:8>


#----------------------------------------------------------#
function [ ret ] = mytest ()

% write a text file
text = '1111 2222 3333 4444 5555 6666';
fid = fopen('myfile','w');
fwrite(fid,text);
fclose(fid);

% fread - works
fid = fopen('myfile','r');
done = fread(fid,[1 Inf],'4*char=>char')
fclose(fid);

% fread with skip - works
fid = fopen('myfile','r');
done = fread(fid,[1 Inf],'4*char=>char',1)
fclose(fid);

% fread with a pipe - works
pid = popen('more myfile','r');
done = fread(pid,[1 Inf],'4*char=>char')
pclose(pid);

% fread with a pipe and a skip - doesn't read it all in
pid = popen('more myfile','r');
done = fread(pid,[1 Inf],'4*char=>char',1)
pclose(pid);

endfunction
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/bug-octave/attachments/20090311/2e5b8462/attachment.html 


More information about the Bug-octave mailing list