diff options
author | prashantsinalkar | 2019-07-04 16:43:43 +0530 |
---|---|---|
committer | prashantsinalkar | 2019-07-04 16:43:43 +0530 |
commit | 70b9ea3f66a7256695ba669cac8d59b515915832 (patch) | |
tree | 62ed9cb4ba123db8927d1431e4668e024505029c | |
parent | 0c28dadc43107d3b06c1dcb2b7a8121520d64f8a (diff) | |
download | R_on_Cloud_Web_API-70b9ea3f66a7256695ba669cac8d59b515915832.tar.gz R_on_Cloud_Web_API-70b9ea3f66a7256695ba669cac8d59b515915832.tar.bz2 R_on_Cloud_Web_API-70b9ea3f66a7256695ba669cac8d59b515915832.zip |
added function for system call execution
-rw-r--r-- | plumber.R | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -34,12 +34,27 @@ function(code="", session_id="") fileConn<-file(InputFile) writeLines(code, fileConn) close(fileConn) - ro <- system(RunInputFile, intern = TRUE) + #ro <- system(RunInputFile, intern = TRUE) + ro <-robust.system(RunInputFile) + ro <- unlist(lapply(ro,function(x) if(identical(x,character(0))) ' ' else x)) fileConn<-file(OutputFile) - writeLines(ro, fileConn) + writeLines(paste0(ro), fileConn) close(fileConn) ro <- read_file(OutputFile) r<- list(status = "SUCCESS", code = "200", output = ro) return (r) } + +robust.system <- function (cmd) { + stderrFile = tempfile(pattern="R_robust.system_stderr", fileext=as.character(Sys.getpid())) + stdoutFile = tempfile(pattern="R_robust.system_stdout", fileext=as.character(Sys.getpid())) + + retval = list() + retval$exitStatus = system(paste0(cmd, " 2> ", shQuote(stderrFile), " > ", shQuote(stdoutFile)), intern = TRUE ) + retval$stdout = readLines(stdoutFile) + retval$stderr = readLines(stderrFile) + + unlink(c(stdoutFile, stderrFile)) + return(retval) +} |