As part of an R program, I have to code Linux "cp" to copy a file. This is Linux ubuntu 17.04. In addition, I have to use sudo. How can I include sudo cp in the code? Here is the script.
I have tried copyCommand<- paste("sudo", "", "cp"), buut I get the message: sudo: no tty present and no askpass program specified
if (paste(dirname(inFileName), "/", sep="") != OUTpath ) {
OS<- Sys.info()["sysname"] # Get OS type
if (OS=="Windows") { # Use OS-specific copy command
copyCommand<- "copy"
} else {
copyCommand<- "cp"
}
paramsCopyFn<- paste(OUTpath, basename(inFileName), sep="")
paramsCopyFn<- sub(".tsv", "_copy.txt", paramsCopyFn, fixed=T)
cmd1<- paste(copyCommand, shQuote(inFileName), shQuote(paramsCopyFn) , sep=" ")
execSystemCmd(cmd1)
}
execSystemCmd<- function(cmd, OS=NULL) {
if (is.null(OS)) OS<- Sys.info()["sysname"] # Get OS type
if (OS=="Windows") { # use OS-secific system shell command wrapper
shell(cmd, translate=TRUE)
} else {
system(cmd)
}