[R] Strange behavior of pipes

Gabor Grothendieck ggrothendieck at myway.com
Wed Nov 12 06:42:35 CET 2003



In R 1.8.0 on Windows 2000 suppose that \a.awk contains:

BEGIN { print "on stdout"
print "on stderr" > "/dev/stderr"
}

which is a simple awk program that writes "on stdout" to stdout
and "on stderr" to stderr.

Then if I start up R I consistently get the following.  That is,
the first pipe does not return anything.  The second pipe returns
a weird character followed by BOTH the stdout and stderr output.
The third pipe does not return anything and then for subsequent
calls we are back to the weird character followed by BOTH the
stdout and stderr output.

I get similar behavior for other programs that use stdout and 
stderr too -- not just gawk.

It looks like a bug to me but I thought I would ask before 
submitting a report in case anyone has any insight into this.

> readLines(pipe("gawk -f \\a.awk"))
character(0)
> readLines(pipe("gawk -f \\a.awk"))
[1] "on stdout" "on stderr" 
> readLines(pipe("gawk -f \\a.awk"))
character(0)
> readLines(pipe("gawk -f \\a.awk"))
[1] "øon stdout" "on stderr" 
> readLines(pipe("gawk -f \\a.awk"))
[1] "Ton stdout" "on stderr" 
> readLines(pipe("gawk -f \\a.awk"))
[1] "on stdout" "on stderr"




More information about the R-help mailing list