1 year ago

#337248

test-img

Arun Bawa

how to pause an R script until cmd prompt is running?

How can I assign with in Rscript to pause until the command prompt is open? I am running a Rscript where a batch file will be executed through command prompt. Later I want to copy a product of executed batch file to another folder. However, Rscript tries to copy while it is being written.

This batch file will open multiple cmd prompts to execute multiple files, so I don't want to use "shell", "system", or "system2" instead of "shell.exec2".

lapply(1:num_cores, function(o) {
  ## batch file location
  loc <- paste0(projectfolder_location, pp, "\\ppfolder_", o, ".Sufi2.SwatCup")
  ## executing batch file
  shell.exec2(paste0(pp_folder, "\\SUFI2_Run.bat")) 
})

#PAUSING HERE until cmd prompt is open!!
file.copy(list.files(
  path=paste0(projectfolder_location, pp, "\\ppfolder_", 1, ".Sufi2.SwatCup"), 
  pattern="Name.out$", full.name=TRUE), projectfolder, overwrite=TRUE)

r

rscript

pause

0 Answers

Your Answer

Accepted video resources