According to the manual, the `stdout` argument of the `system2`
function can redirect output to a file. This seems to work on unix,
however I can't get it to work on windows. The toy example below, no
`out.txt` or `err.txt` files are created. I tried sending it to an
existing file, or expand the full file path, but with no success:
setwd(tempdir())
system2("whoami", stdout="out.txt", stderr="err.txt")
file.exists("out.txt")
Am I doing something wrong or is this not supported on windows?
Redirect system2 stdout to a file on windows
5 messages · Jeroen Ooms, Gabor Grothendieck, Henrik Bengtsson
On Sun, Jul 14, 2013 at 1:18 PM, Jeroen Ooms <jeroen.ooms at stat.ucla.edu> wrote:
According to the manual, the `stdout` argument of the `system2`
function can redirect output to a file. This seems to work on unix,
however I can't get it to work on windows. The toy example below, no
`out.txt` or `err.txt` files are created. I tried sending it to an
existing file, or expand the full file path, but with no success:
setwd(tempdir())
system2("whoami", stdout="out.txt", stderr="err.txt")
file.exists("out.txt")
Am I doing something wrong or is this not supported on windows?
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Try:
out.txt <- normalizePath("./out.txt", mustWork = FALSE)
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
On Sun, Jul 14, 2013 at 10:24 PM, Gabor Grothendieck wrote:
Try:
out.txt <- normalizePath("./out.txt", mustWork = FALSE)
Doesn't work either, neither on Win7 nor WinXP.
sessionInfo()
R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)
On Sun, Jul 14, 2013 at 5:20 PM, Jeroen Ooms <jeroen.ooms at stat.ucla.edu> wrote:
On Sun, Jul 14, 2013 at 10:24 PM, Gabor Grothendieck wrote:
Try:
out.txt <- normalizePath("./out.txt", mustWork = FALSE)
Doesn't work either, neither on Win7 nor WinXP.
sessionInfo()
R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)
Not sure what happened but I tried it again and it did not work on my
system either.
If a workaround is ok then this works on my system:
shell(paste("whoami", ">", "out.txt"))
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
Works for me (Win 7 64bit) using R.exe:
setwd(tempdir()) getwd()
[1] "C:/Users/hb/AppData/Local/Temp/RtmpSqjCDt"
res <- system2("whoami", stdout="out.txt", stderr="err.txt")
res
[1] 0
file.info(c("out.txt", "err.txt"))
size isdir mode mtime ctime
out.txt 12 FALSE 666 2013-07-15 00:02:06 2013-07-15 00:02:02
err.txt 0 FALSE 666 2013-07-15 00:02:06 2013-07-15 00:02:02
atime exe
out.txt 2013-07-15 00:02:02 no
err.txt 2013-07-15 00:02:02 no
sessionInfo()
R version 3.0.1 Patched (2013-07-10 r63264) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.0.1 /Henrik On Mon, Jul 15, 2013 at 12:01 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
On Sun, Jul 14, 2013 at 5:20 PM, Jeroen Ooms <jeroen.ooms at stat.ucla.edu> wrote:
On Sun, Jul 14, 2013 at 10:24 PM, Gabor Grothendieck wrote:
Try:
out.txt <- normalizePath("./out.txt", mustWork = FALSE)
Doesn't work either, neither on Win7 nor WinXP.
sessionInfo()
R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)
Not sure what happened but I tried it again and it did not work on my
system either.
If a workaround is ok then this works on my system:
shell(paste("whoami", ">", "out.txt"))
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel