[R] Terminating a cmd windows from R

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Sat Aug 17 16:07:25 CEST 2024


В Sat, 17 Aug 2024 11:47:30 +0000
SIMON Nicolas via R-help <r-help using r-project.org> пишет:

> nmrun <- paste0("cmd.exe /k ",nm_log,".bat ",nmi,".ctl ",nmi,".lst")

You are using the /k option that instructs cmd.exe to keep the command
prompt open. Does the batch file contain an explicit "exit" to ensure
that cmd.exe terminates?

> system(nmrun, invisible = F, show.output.on.console = T, wait = T)

With wait = TRUE, it should be possible to interrupt the process by
pressing Ctrl+C in the cmd.exe window, but R itself will not be running
your commands until system() returns (or is interrupted, terminating
the process). You can specify a timeout for a foreground process using
the 'timeout' argument of the system() function.

If you'd like to manage a background process, consider the 'processx'
CRAN package: https://cran.r-project.org/package=processx

-- 
Très cordialement,
Ivan



More information about the R-help mailing list