Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: tags/R-2-13-0
Fetching contributors…

Cannot retrieve contributors at this time

file 285 lines (249 sloc) 5.39 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

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"
>
Something went wrong with that request. Please try again.