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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to