[R] system vs shell wait command
Duncan Murdoch
murdoch at stats.uwo.ca
Sun Jan 24 13:53:30 CET 2010
On 24/01/2010 7:25 AM, robbert blonk wrote:
> Dear All,
>
> I try to invoke a second program (called "gencont") within a R script.
> However this second program needs some time to finish. After finishing the
> output should be read into R and used for further calculation.
>
> Under windows, it perfectly works:
>
> result<-shell("gencont < yn.txt",intern=TRUE,wait=TRUE)
> # R waits untill the program finishes (apporx 3 min) and uses the result as
> an object. "yn.txt" contains the answer to a question prompted by the second
> program before running
> resultf<-result[length(result)]
> # reads the last line, which contains the required result
>
> However, At our Linux server, shell() doesn't work. Here, I'll need
> system()...
> result<-system("./gencont.exe < yn.txt",intern=TRUE,wait=TRUE) #slightly
> different
> resultf<-result[length(result)] #same
>
> The problem now is that R under Linux does not wait for the second program
> to finish, even if wait = TRUE...how come?
> What should I do?
You could use a pipe, for example:
resultf <- readLines(pipe("./gencont.exe < yn.txt"))
Duncan Murdoch
More information about the R-help
mailing list