www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.stream.stdin.eof() and pipes - do they work together?

reply Jay <Jay_member pathlink.com> writes:
Hi, 
 
I'm using gdc-0.11 which uses the last version of phobos (the one that
comes 
with dmd 0.121) and have a problem with the following program. (I think
this 
is a problem with phobos and not gdc, which is why I'm posting here, but I
may 
be wrong.) 
 




char[] s; 


std.stream.stdin.readLine(); 




When running the program as "./a.out < somefile" the program correctly copies
input to output, but when running the program as "cat somefile | ./a.out" the
program aborts with the message "Error: Stream is not seekable". 
 
On the other
hand, the following C program works without error for both cases. 
 

<sys/types.h> 








(!feof(stdin)) { 





 
Some
snooping inside std/stream.d shows that eof() uses the size of a file and 
the
current position in the file, which I imagine wouldn't work with pipes 
because
they aren't seekable. 
 
Is there a simple solution to my problem: use eof() and
readLine() on 
std.stream.stdin with pipes, or should I just build my own
readLine() out of C 
functions? 
 
Thanks, 
Jay 
Apr 30 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
Piped streams are busted in 120 and 121. There is a fix sitting in Walter 
in-box but until that hits the net I'd recommend recompiling phobos with the 
"assertSeekable" function commented out to be a no-op. The issue is that it 
turned out piped streams depended on being able to seek on streams marked as 
seekable==false.
sorry for the trouble!
-Ben

"Jay" <Jay_member pathlink.com> wrote in message 
news:d519kh$1ilu$1 digitaldaemon.com...
 Hi,

 I'm using gdc-0.11 which uses the last version of phobos (the one that
 comes
 with dmd 0.121) and have a problem with the following program. (I think
 this
 is a problem with phobos and not gdc, which is why I'm posting here, but I
 may
 be wrong.)





 char[] s;


 std.stream.stdin.readLine();




 When running the program as "./a.out < somefile" the program correctly 
 copies
 input to output, but when running the program as "cat somefile | ./a.out" 
 the
 program aborts with the message "Error: Stream is not seekable".

 On the other
 hand, the following C program works without error for both cases.


 <sys/types.h>








 (!feof(stdin)) {






 Some
 snooping inside std/stream.d shows that eof() uses the size of a file and
 the
 current position in the file, which I imagine wouldn't work with pipes
 because
 they aren't seekable.

 Is there a simple solution to my problem: use eof() and
 readLine() on
 std.stream.stdin with pipes, or should I just build my own
 readLine() out of C
 functions?

 Thanks,
 Jay

 
Apr 30 2005
parent Jay <Jay_member pathlink.com> writes:
In article <d51auc$1jmo$1 digitaldaemon.com>, Ben Hinkle says... 
 
Piped
streams are busted in 120 and 121. There is a fix sitting in Walter
in-box
but until that hits the net I'd recommend recompiling phobos with the
"assertSeekable" function commented out to be a no-op. The issue is that it  
turned out piped streams depended on being able to seek on streams marked as  
seekable==false. 
sorry for the trouble! 
Thanks Ben, It's only a small interruption. Jay
Apr 30 2005