From b6e8cdde24591219e5e97b1009b79f549e263761 Mon Sep 17 00:00:00 2001 From: Lukas Burk Date: Fri, 5 Dec 2025 16:39:18 +0100 Subject: [PATCH 1/6] Try shQuote fix for SSH --- R/runOSCommand.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/runOSCommand.R b/R/runOSCommand.R index c410c126..07e2166a 100644 --- a/R/runOSCommand.R +++ b/R/runOSCommand.R @@ -30,9 +30,9 @@ runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", nodename if (!isLocalHost(nodename)) { command = sprintf("%s %s", sys.cmd, stri_flatten(sys.args, " ")) - if (getRversion() < "4.0.0") { - command = shQuote(command) - } + # if (getRversion() < "4.0.0") { + command = shQuote(command) + # } command = stri_replace_all_fixed(command, "\\$", "$") sys.args = c("-q", nodename, command) sys.cmd = "ssh" From 4e01046d2dec2acf78ccc9eab21319413775cc72 Mon Sep 17 00:00:00 2001 From: Lukas Burk Date: Sat, 6 Dec 2025 18:49:51 +0100 Subject: [PATCH 2/6] Fix missing script assignment in Worker for non-localhost --- R/Worker.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/Worker.R b/R/Worker.R index ba53459c..cd857825 100644 --- a/R/Worker.R +++ b/R/Worker.R @@ -52,6 +52,7 @@ Worker = R6Class("Worker", if (!testString(script, min.chars = 1L)) { stopf("Unable to locate helper script on SSH node '%s'. Is batchtools installed on the node?", nodename) } + self$script = script } self$ncpus = ncpus %??% as.integer(private$run("number-of-cpus")$output) From 16a889a6a7d53adfc735393d7e709241dd932564 Mon Sep 17 00:00:00 2001 From: Lukas Burk Date: Sat, 6 Dec 2025 18:50:56 +0100 Subject: [PATCH 3/6] Update NEWS --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 72488780..68af85ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # batchtools 0.9.17 * Fixed a bug in the finalizer of `ClusterFunctionsMulticore`. +* Fixed a bug in `Worker` initialization where the script path was not assigned for remote SSH hosts, causing `runOSCommand()` to fail with NULL argument. # batchtools 0.9.16 From cfa63549f685233b0d0c413a3cbd2035d0dcb7eb Mon Sep 17 00:00:00 2001 From: Lukas Burk Date: Sat, 6 Dec 2025 18:54:29 +0100 Subject: [PATCH 4/6] NEWS, comments --- NEWS.md | 5 ++++- R/runOSCommand.R | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 68af85ee..94d526ab 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,10 @@ +# batchtools (development version) + +* Fixed a bug in `Worker` initialization where the script path was not assigned for remote SSH hosts, causing `runOSCommand()` to fail with NULL argument. + # batchtools 0.9.17 * Fixed a bug in the finalizer of `ClusterFunctionsMulticore`. -* Fixed a bug in `Worker` initialization where the script path was not assigned for remote SSH hosts, causing `runOSCommand()` to fail with NULL argument. # batchtools 0.9.16 diff --git a/R/runOSCommand.R b/R/runOSCommand.R index 07e2166a..ded38fef 100644 --- a/R/runOSCommand.R +++ b/R/runOSCommand.R @@ -23,16 +23,20 @@ #' runOSCommand("ls", "-al") #' runOSCommand("notfound") #' } -runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", nodename = "localhost") { +runOSCommand = function( + sys.cmd, + sys.args = character(0L), + stdin = "", + nodename = "localhost" +) { assertCharacter(sys.cmd, any.missing = FALSE, len = 1L) assertCharacter(sys.args, any.missing = FALSE) assertString(nodename, min.chars = 1L) if (!isLocalHost(nodename)) { command = sprintf("%s %s", sys.cmd, stri_flatten(sys.args, " ")) - # if (getRversion() < "4.0.0") { + # The shQuote'ing appears to be necessary even on R >= 4.5 command = shQuote(command) - # } command = stri_replace_all_fixed(command, "\\$", "$") sys.args = c("-q", nodename, command) sys.cmd = "ssh" @@ -41,7 +45,14 @@ runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", nodename "!DEBUG [runOSCommand]: cmd: `sys.cmd` `stri_flatten(sys.args, ' ')`" if (nzchar(Sys.which(sys.cmd))) { - res = suppressWarnings(system2(command = sys.cmd, args = sys.args, stdin = stdin, stdout = TRUE, stderr = TRUE, wait = TRUE)) + res = suppressWarnings(system2( + command = sys.cmd, + args = sys.args, + stdin = stdin, + stdout = TRUE, + stderr = TRUE, + wait = TRUE + )) output = as.character(res) exit.code = attr(res, "status") %??% 0L } else { @@ -52,7 +63,12 @@ runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", nodename "!DEBUG [runOSCommand]: OS result (stdin '`stdin`', exit code `exit.code`):" "!DEBUG [runOSCommand]: `paste0(output, sep = '\n')`" - return(list(sys.cmd = sys.cmd, sys.args = sys.args, exit.code = exit.code, output = output)) + return(list( + sys.cmd = sys.cmd, + sys.args = sys.args, + exit.code = exit.code, + output = output + )) } isLocalHost = function(nodename) { @@ -60,9 +76,16 @@ isLocalHost = function(nodename) { } OSError = function(msg, res) { - cmd = stri_flatten(c(res$sys.cmd, res$sys.args), collapse = " ") %??% NA_character_ + cmd = stri_flatten(c(res$sys.cmd, res$sys.args), collapse = " ") %??% + NA_character_ exit.code = res$exit.code %??% NA_integer_ output = stri_flatten(res$output, "\n") %??% "" - stopf("%s (exit code %i);\ncmd: '%s'\noutput:\n%s", msg, exit.code, cmd, output) + stopf( + "%s (exit code %i);\ncmd: '%s'\noutput:\n%s", + msg, + exit.code, + cmd, + output + ) } From 3d15695aa17d51f27faedba1a12c090a76f76cbe Mon Sep 17 00:00:00 2001 From: Lukas Burk Date: Sat, 6 Dec 2025 19:07:30 +0100 Subject: [PATCH 5/6] Avoid formatting --- R/runOSCommand.R | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/R/runOSCommand.R b/R/runOSCommand.R index ded38fef..226b8458 100644 --- a/R/runOSCommand.R +++ b/R/runOSCommand.R @@ -23,12 +23,7 @@ #' runOSCommand("ls", "-al") #' runOSCommand("notfound") #' } -runOSCommand = function( - sys.cmd, - sys.args = character(0L), - stdin = "", - nodename = "localhost" -) { +runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", nodename = "localhost") { assertCharacter(sys.cmd, any.missing = FALSE, len = 1L) assertCharacter(sys.args, any.missing = FALSE) assertString(nodename, min.chars = 1L) @@ -45,14 +40,7 @@ runOSCommand = function( "!DEBUG [runOSCommand]: cmd: `sys.cmd` `stri_flatten(sys.args, ' ')`" if (nzchar(Sys.which(sys.cmd))) { - res = suppressWarnings(system2( - command = sys.cmd, - args = sys.args, - stdin = stdin, - stdout = TRUE, - stderr = TRUE, - wait = TRUE - )) + res = suppressWarnings(system2(command = sys.cmd, args = sys.args, stdin = stdin, stdout = TRUE, stderr = TRUE, wait = TRUE)) output = as.character(res) exit.code = attr(res, "status") %??% 0L } else { @@ -63,12 +51,7 @@ runOSCommand = function( "!DEBUG [runOSCommand]: OS result (stdin '`stdin`', exit code `exit.code`):" "!DEBUG [runOSCommand]: `paste0(output, sep = '\n')`" - return(list( - sys.cmd = sys.cmd, - sys.args = sys.args, - exit.code = exit.code, - output = output - )) + return(list(sys.cmd = sys.cmd, sys.args = sys.args, exit.code = exit.code, output = output)) } isLocalHost = function(nodename) { @@ -76,16 +59,9 @@ isLocalHost = function(nodename) { } OSError = function(msg, res) { - cmd = stri_flatten(c(res$sys.cmd, res$sys.args), collapse = " ") %??% - NA_character_ + cmd = stri_flatten(c(res$sys.cmd, res$sys.args), collapse = " ") %??% NA_character_ exit.code = res$exit.code %??% NA_integer_ output = stri_flatten(res$output, "\n") %??% "" - stopf( - "%s (exit code %i);\ncmd: '%s'\noutput:\n%s", - msg, - exit.code, - cmd, - output - ) + stopf("%s (exit code %i);\ncmd: '%s'\noutput:\n%s", msg, exit.code, cmd, output) } From bd5655906fa831c1726f7c508ec2caf2e3aa5a6f Mon Sep 17 00:00:00 2001 From: Lukas Burk Date: Sat, 6 Dec 2025 19:08:36 +0100 Subject: [PATCH 6/6] Update DESCRIPTION --- DESCRIPTION | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b07baafb..e5fde1e9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,14 @@ Package: batchtools Title: Tools for Computation on Batch Systems -Version: 0.9.18 +Version: 0.9.19 Authors@R: c( person("Michel", "Lang", , "michellang@gmail.com", role = c("cre", "aut"), comment = c(ORCID = "0000-0001-9754-0393")), person("Bernd", "Bischl", , "bernd_bischl@gmx.net", role = "aut"), person("Dirk", "Surmann", , "surmann@statistik.tu-dortmund.de", role = "ctb", - comment = c(ORCID = "0000-0003-0873-137X")) + comment = c(ORCID = "0000-0003-0873-137X")), + person("Lukas", "Burk", , "sgithub@quantenbrot.de", role = "ctb", + comment = c(ORCID = "0000-0001-7528-3795")) ) Description: As a successor of the packages 'BatchJobs' and 'BatchExperiments', this package provides a parallel implementation of