From 70b9ea3f66a7256695ba669cac8d59b515915832 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 4 Jul 2019 16:43:43 +0530 Subject: added function for system call execution --- plumber.R | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plumber.R b/plumber.R index e5d47b3..0226024 100644 --- a/plumber.R +++ b/plumber.R @@ -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) +} -- cgit