如何暂停 R 脚本直到 cmd 提示符运行?

发布于 2025-01-16 22:28:49 字数 667 浏览 5 评论 0原文

如何在 Rscript 中指定 暂停,直到命令提示符打开? 我正在运行 Rscript,其中将通过命令提示符执行批处理文件。后来我想将执行批处理文件的产品复制到另一个文件夹。然而,Rscript 会在写入时尝试进行复制。

这个批处理文件将打开多个cmd提示符来执行多个文件,因此我不想使用“shell”、“system”或“system2”来代替“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)

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
quot;, full.name=TRUE), projectfolder, overwrite=TRUE)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文