[Rd] problem with pipes (PR#5053)

Gabor Grothendieck ggrothendieck at myway.com
Thu Dec 25 15:14:30 MET 2003



I gather that the pipe problem is a difficult one to solve
since its highly desirable (at least for me) to be able to
use Windows pipes yet its been outstanding since the previous
R release.

I have one idea on a possible workaround and associated 
feature and I wonder if this feature is feasible?  
I just noticed that

z <- system("c:\\a.bat", intern = TRUE, invisible = TRUE)

is similar in function to:

z <- readLines(pipe("c:\\a.bat"))

One problem is that it appears to return both stdout and stderr.
Would the underlying Windows system call that is used by
the R command, system, allow for specification of a flag 
that determines whether stdout, stderr or both are returned?
If so, adding access to this flag from the R level, e.g.

z <- system("c:\\a.bat", intern = T, invisible = T, 
                 stderr = F, stdout = T)

might be sufficient for this to be used in place of pipes
in many applications.

----
[Rd] problem with pipes (PR#5053)
ggrothendieck at myway.com ggrothendieck at myway.com 
Wed Nov 12 23:43:35 MET 2003 

Full_Name: Gabor Grothendieck
Version: 1.8.0
OS: Windows 2000 Pro
Submission from: (NULL) (67.68.47.99)



In R 1.8.0 on Windows 2000 suppose that \a.bat contains the following two
lines:

net /? 
dir \winnt

which constitutes a simple batch file which 
1. writes a help message about the built in Windows net command to stderr and 
2. does a dir on the built in Windows directory WINNT writing result to stdout

You can replace #1 with any other command which outputs to stderr and #2 with
any other command that outputs to stdout.  I just chose those commands since
they come with Windows.

If you start up R and run a pipe which executes \a.bat one gets
the following werid behavior on Windows 2000:

> readLines(pipe("\\a.bat"))
 [1] ""                                                                    
 [2] "C:\\Program Files\\R\\rw1080>net /? "                                 
 [3] "The syntax of this command is:"                                       
 [4] ""                                                                     
 [5] ""                                                                     
 [6] ""                                                                     
 [7] ""                                                                     
 [8] "NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |"
 [9] "      HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |" 
[10] "      SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]" 
[11] ""                                                                     
[12] ""                                                                     
[13] "C:\\Program Files\\R\\rw1080>dir \\a.bat "                            
[14] " Volume in drive C has no label."                                     
[15] " Volume Serial Number is 07D1-011A"                                   
[16] ""                                                                     
[17] " Directory of C:\\"                                                   
[18] ""                                                                     
[19] "11/12/2003  05:07p                  20 a.bat"                         
[20] "               1 File(s)             20 bytes"                        
[21] "               0 Dir(s)     484,712,448 bytes free"  


There are several problems:

1. I am getting both the stderr (the output from net /?) and the stdout
   (the output from dir).

2. The first line contains a weird character.  This character changes if
I perform the R command multiple times.

3. Usually I get the above but sometimes I get no output from readLines at
all.

I found this when I was trying to pipe output from a command (not the above
batch file which is just an simpler example) to R and finally traced it the 
above.

The above is sufficiently serious that I can't use pipes in R currently
on Windows 2000.

I am using R 1.8.0 but R 1.7.1 gives the same.

I had previously posted a version of this to r-help just to verify whether it
was a bug or not but no one answered so I guess it is.  My r-help message
used gawk instead of a batch file to illustrate this behavior.  See:

https://www.stat.math.ethz.ch/pipermail/r-help/2003-November/040426.html



More information about the R-devel mailing list