[R] capturing output from Win 98 shell

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Aug 12 16:48:54 CEST 2003


Simon Fear wrote:

> How can I best achieve the following (works in Splus):
> 
> filenames <- dos("dir *.sasb7dat /b")
> 
> What I am  asking, more generically, is: how can I capture the output of
> a
> DOS command in R?
> 
> I have tried using
> 
> system("COMMAND.COM /c dir /b", intern=T, show.output.on.console=T)
> 
> where
> 
>   intern: a logical, indicates whether to make the output of the
>           command an R object.
> 
> but it makes no useful difference:
> 
> 
>>system("COMMAND.COM /c dir /b", intern=T, show.output.on.console=T)
> 
> character(0)
> 
>>print(system("COMMAND.COM /c dir /b", intern=F,
> 
> show.output.on.console=T))
> [1] 0
> 
> In both cases here a DOS window opens and lists a couple of hundred
> files,
> before giving the above output.
> 
> I am also a bit baffled by "show.output.on.console" whose only effect
> seems
> to be on whether the DOS screen opens for one millisecond or for one
> second.
> It does not, per help, "show the output of the command on the R
> console".
> 
> Incidentally I can answer the problem at hand using the following
> workaround
> (but what I'm after is a more generic solution):
> 
> shell("dir D:\\tmp\\*.sasb7dat /b > D:\\tmp\\Paula\\dirlist.lst")
> dataset.names <- scan("D:\\tmp\\dirlist.lst", what="", sep="\n")


So you almost got it, just read ?shell carefully enough:

  filenames <- shell("dir D:\\tmp\\*.sasb7dat /b", intern = TRUE)

or even better in this case:

  filenames <- list.files("d:/tmp", pattern = "sasb7dat")

Uwe Ligges


> TIA
> SF
>  
> 
> Simon Fear
> Senior Statistician
> Syne qua non Ltd
> Tel: +44 (0) 1379 644449
> Fax: +44 (0) 1379 644445
> email: Simon.Fear at synequanon.com
> web: http://www.synequanon.com
>  
> Number of attachments included with this message: 0
>  
> This message (and any associated files) is confidential and\...{{dropped}}
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list