我正在尝试从R(在Ubuntu上为3.3.1)执行shell命令,如下所示:
system2(command="ls",
args=c("-l", "/etc/"),
stdout="/tmp/stdout.log",
stderr="/tmp/stderr.log",
wait=TRUE)
不幸的是,每次执行此操作时,日志文件的内容都会被覆盖。我们可以以某种方式指定它执行附加操作而不是覆盖操作吗?
而且,由于它允许使用更现代的系统命令并允许进行更清晰的日志记录,因此它甚至更好。
result <- system2(command="ls",
args=c("-l", "/etc/"),
stdout="/tmp/stdout.log",
stderr="/tmp/stderr.log",
wait=TRUE)
now <- date()
cat(paste0("Executed: ", now, "\n"), file="/tmp/stdoutmain.log", append=TRUE)
file.append("/tmp/stdoutmain.log", "/tmp/stdout.log")
cat(paste0("Executed: ", now, "\n"), file="/tmp/stderrmain.log", append=TRUE)
file.append("/tmp/stderrmain.log", "/tmp/stderr.log")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句