I execute a program using a batch file from R. The program may have infinite computation. So I need to be avle to stop it. nm_log <- "c:/nm74g64/run/nmfe74" nmi <- "202" nmrun <- paste0("cmd.exe /k ",nm_log,".bat ",nmi,".ctl ",nmi,".lst") # run system(nmrun, invisible = F, show.output.on.console = T, wait = T) Le 17 ao?t 2024 ? 13:31, Duncan Murdoch <murdoch.duncan at gmail.com> a ?crit : ? On 2024-08-17 6:?21 a.?m.?, SIMON Nicolas via R-help wrote: > I would like to stop a dos shell windows following the cmd (execute) command. Is there a way to do that from R? I think you need to give more detail on what you are trying to do.? On 2024-08-17 6:21 a.m., SIMON Nicolas via R-help wrote:> I would like to stop a dos shell windows following the cmd (execute) command. Is there a way to do that from R?I think you need to give more detail on what you are trying to do. In Windows, "cmd" is supposed to open a shell window. Could you show us an example of what you are doing? Duncan Murdoch
? Sat, 17 Aug 2024 11:47:30 +0000 SIMON Nicolas via R-help <r-help at 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