
R version 2.13.0 Under development (unstable) (2010-11-15 r53605)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ## tests of options in system() and system2.
> 
> options(warn = 1)
> 
> opts <- list("", NULL, FALSE, TRUE, "o1.txt", "o2.txt")
> outs <- c("o1.txt", "o2.txt")
> 
> process <- function(res)
+ {
+     unlink(outs)
+     if(is.character(res)) {
+         cat("value:\n")
+         writeLines(res)
+     }
+     for(f in outs)
+         if(file.exists(f)) {
+             cat(f, ":\n", sep = "")
+             writeLines(readLines(f))
+         }
+ }
> 
> for(out in opts)
+     for(err in opts) {
+         ## skip this for the sake of Unix-alikes
+         if(identical(err, TRUE) && !identical(out,TRUE)) next
+         cat(sprintf("\ntesting stdout = %s, stderr = %s\n",
+             deparse(out), deparse(err)))
+         process(system2("test-system2", stdout = out, stderr = err))
+     }

testing stdout = "", stderr = ""
stdout 1
stderr 1

testing stdout = "", stderr = NULL
stdout 1

testing stdout = "", stderr = FALSE
stdout 1

testing stdout = "", stderr = "o1.txt"
stdout 1
o1.txt:
stderr 1

testing stdout = "", stderr = "o2.txt"
stdout 1
o2.txt:
stderr 1

testing stdout = NULL, stderr = ""
stderr 1

testing stdout = NULL, stderr = NULL

testing stdout = NULL, stderr = FALSE

testing stdout = NULL, stderr = "o1.txt"
o1.txt:
stderr 1

testing stdout = NULL, stderr = "o2.txt"
o2.txt:
stderr 1

testing stdout = FALSE, stderr = ""
stderr 1

testing stdout = FALSE, stderr = NULL

testing stdout = FALSE, stderr = FALSE

testing stdout = FALSE, stderr = "o1.txt"
o1.txt:
stderr 1

testing stdout = FALSE, stderr = "o2.txt"
o2.txt:
stderr 1

testing stdout = TRUE, stderr = ""
stderr 1
value:
stdout 1

testing stdout = TRUE, stderr = NULL
value:
stdout 1

testing stdout = TRUE, stderr = FALSE
value:
stdout 1

testing stdout = TRUE, stderr = TRUE
value:
stdout 1
stderr 1

testing stdout = TRUE, stderr = "o1.txt"
value:
stdout 1
o1.txt:
stderr 1

testing stdout = TRUE, stderr = "o2.txt"
value:
stdout 1
o2.txt:
stderr 1

testing stdout = "o1.txt", stderr = ""
stderr 1
o1.txt:
stdout 1

testing stdout = "o1.txt", stderr = NULL
o1.txt:
stdout 1

testing stdout = "o1.txt", stderr = FALSE
o1.txt:
stdout 1

testing stdout = "o1.txt", stderr = "o1.txt"
o1.txt:
stdout 1
stderr 1

testing stdout = "o1.txt", stderr = "o2.txt"
o1.txt:
stdout 1
o2.txt:
stderr 1

testing stdout = "o2.txt", stderr = ""
stderr 1
o2.txt:
stdout 1

testing stdout = "o2.txt", stderr = NULL
o2.txt:
stdout 1

testing stdout = "o2.txt", stderr = FALSE
o2.txt:
stdout 1

testing stdout = "o2.txt", stderr = "o1.txt"
o1.txt:
stderr 1
o2.txt:
stdout 1

testing stdout = "o2.txt", stderr = "o2.txt"
o2.txt:
stdout 1
stderr 1
> 
> 
> process(system("test-system2"))
stdout 1
stderr 1
> process(system("test-system2", ignore.stdout = TRUE))
stderr 1
> process(system("test-system2", ignore.stderr = TRUE))
stdout 1
> process(system("test-system2", ignore.stdout = TRUE, ignore.stderr = TRUE))
> 
> process(system("test-system2", TRUE))
stderr 1
value:
stdout 1
> process(system("test-system2", TRUE, ignore.stdout = TRUE))
stderr 1
value:
> process(system("test-system2", TRUE, ignore.stdout = TRUE, ignore.stderr = TRUE))
value:
> 
> process(system2("test-system2", "1", input=letters[1:4]))
stdout 1
stderr 1
stdin: a
stdin: b
stdin: c
stdin: d
> process(system2("test-system2", "1", input=letters[1:4], stdout = TRUE))
stderr 1
value:
stdout 1
stdin: a
stdin: b
stdin: c
stdin: d
> 
> process(system("test-system2 1", input=letters[1:4]))
stdout 1
stderr 1
stdin: a
stdin: b
stdin: c
stdin: d
> process(system("test-system2 1", input=letters[1:4], intern = TRUE))
stderr 1
value:
stdout 1
stdin: a
stdin: b
stdin: c
stdin: d
> 
> tmp <- tempfile()
> writeLines(letters[5:7], tmp)
> process(system2("test-system2", "1", stdin = tmp))
stdout 1
stderr 1
stdin: e
stdin: f
stdin: g
> process(system2("test-system2", "1", stdin = tmp, stdout = TRUE))
stderr 1
value:
stdout 1
stdin: e
stdin: f
stdin: g
> process(system2("test-system2", "1", stdin = tmp, stdout = TRUE, stderr = TRUE))
value:
stdout 1
stderr 1
stdin: e
stdin: f
stdin: g
> process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt", stderr = "o1.txt"))
o1.txt:
stdout 1
stderr 1
stdin: e
stdin: f
stdin: g
> process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt", stderr = "o2.txt"))
o1.txt:
stdout 1
stdin: e
stdin: f
stdin: g
o2.txt:
stderr 1
> 
> unlink(c(tmp, outs))
> 
> print(system("test-system2 5"))
stdout 1
stderr 1
[1] 5
> system("test-system2 6", intern = TRUE)
stderr 1
Warning: running command 'test-system2 6' had status 6
[1] "stdout 1"
> print(system2("test-system2", "7"))
stdout 1
stderr 1
[1] 7
> system2("test-system2", "8", stdout=TRUE)
stderr 1
Warning: running command ''test-system2' 8' had status 8
[1] "stdout 1"
> 
