Thread overview
std.stream.stdin.eof() and pipes - do they work together?
May 01, 2005
Jay
May 01, 2005
Ben Hinkle
May 01, 2005
Jay
May 01, 2005
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.)

# import std.stream, std.stdio;
#
# int main() {
#
char[] s;
# 	while (!std.stream.stdin.eof) {
# 		s =
std.stream.stdin.readLine();
# 		writefln("%s", s);
# 	}
# 	return 0;
# }
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.

# #include
<sys/types.h>
# #include <unistd.h>
# #include <stdio.h>
#
# int main() {
# 	char s[32];
# 	while (!feof(stdin)) {
# 		fgets(s, 32, stdin);
# 		if
(!feof(stdin)) {
# 			printf("%s", s);
# 		}
# 	}
# 	return 0;
# }

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


May 01, 2005
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.)
>
> # import std.stream, std.stdio;
> #
> # int main() {
> #
> char[] s;
> # while (!std.stream.stdin.eof) {
> # s =
> std.stream.stdin.readLine();
> # writefln("%s", s);
> # }
> # return 0;
> # }
> 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.
>
> # #include
> <sys/types.h>
> # #include <unistd.h>
> # #include <stdio.h>
> #
> # int main() {
> # char s[32];
> # while (!feof(stdin)) {
> # fgets(s, 32, stdin);
> # if
> (!feof(stdin)) {
> # printf("%s", s);
> # }
> # }
> # return 0;
> # }
>
> 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
>
> 


May 01, 2005
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