Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runOSCommand throws error with R 4.0 (missing shQuote) #264

Open
aschersleben opened this issue Jul 17, 2020 · 2 comments
Open

runOSCommand throws error with R 4.0 (missing shQuote) #264

aschersleben opened this issue Jul 17, 2020 · 2 comments

Comments

@aschersleben
Copy link

Hi,
I'm working on a debian server and try to use makeClusterFunctionsSSH(...) to distribute jobs to other debian servers. It throws the following error:
syntax error near unexpected token `('
The error is caused by runOSCommand(...).
In 75a5b70 you removed the shQuote for R 4.0 and higher. But as far as I was able to reproduce the error, this shQuote is still needed with R 4.0.2.

MWE directly built from the code of Worker and runOSCommand:
(you have to set the nodename variable)

library(batchtools)
### error:

nodename = "XXXXX"
sys.args = c("-e", shQuote("message(\"[bt] --BOF--\\n\", \"[bt] \", system.file(\"bin/linux-helper\", package = \"batchtools\"), \"\\n[bt] --EOF--\\n\")"))
sys.cmd = "Rscript"
checkmate::assertCharacter(sys.cmd, any.missing = FALSE, len = 1L)
checkmate::assertCharacter(sys.args, any.missing = FALSE)
checkmate::assertString(nodename, min.chars = 1L)
command = sprintf("%s %s", sys.cmd, stringi::stri_flatten(sys.args, " "))
command = stringi::stri_replace_all_fixed(command, "\\$", "$")
sys.args = c("-q", nodename, command)
sys.cmd = "ssh"
system2(command = sys.cmd, args = sys.args, stdin = "", stdout = TRUE, stderr = TRUE, wait = TRUE)
#> Warning in system2(command = sys.cmd, args = sys.args, stdin = "", stdout =
#> TRUE, : running command ''ssh' -q XXXXX
#> Rscript -e 'message("[bt] --BOF--\n", "[bt] ", system.file("bin/linux-helper",
#> package = "batchtools"), "\n[bt] --EOF--\n")' 2>&1' had status 1
#> [1] "bash: -c: line 0: syntax error near unexpected token `('"                                                                                                   
#> [2] "bash: -c: line 0: `Rscript -e message(\"[bt] --BOF--\\n\", \"[bt] \", system.file(\"bin/linux-helper\", package = \"batchtools\"), \"\\n[bt] --EOF--\\n\")'"
#> attr(,"status")
#> [1] 1


#### works:

command = shQuote(command)
sys.args = c("-q", nodename, command)
sys.cmd = "ssh"
system2(command = sys.cmd, args = sys.args, stdin = "", stdout = TRUE, stderr = TRUE, wait = TRUE)
#> [1] "[bt] --BOF--"                                                               
#> [2] "[bt] /home/pa/R/x86_64-pc-linux-gnu-library/4.0/batchtools/bin/linux-helper"
#> [3] "[bt] --EOF--"                                                               
#> [4] ""

Created on 2020-07-17 by the reprex package (v0.3.0)

Can you reproduce this?

@franzbischoff
Copy link

franzbischoff commented Aug 23, 2021

I was just opening another issue, but I see it is already found.

My lazy repro is:

doesn't work

args <- c("-e", shQuote("message(\"[bt] --BOF--\\n\", \"[bt] \", system.file(\"bin/linux-helper\", 
  package = \"batchtools\"), \"\\n[bt] --EOF--\\n\")"))
command <- sprintf("%s %s", "Rscript", stringi::stri_flatten(args, " "))
# command = shQuote(command)
command <- stringi::stri_replace_all_fixed(command, "\\$", "$")
sys.args <- c("-q", "myremotehost", command)
sys.cmd <- "ssh"
res <- suppressWarnings(system2(command = sys.cmd, args = sys.args, stdin = "", 
   stdout = TRUE, stderr = TRUE, wait = TRUE))
output <- as.character(res)
output

[1] "bash: -c: line 0: syntax error near the symbol \"(\" unexpected"

works

args <- c("-e", shQuote("message(\"[bt] --BOF--\\n\", \"[bt] \", system.file(\"bin/linux-helper\", 
  package = \"batchtools\"), \"\\n[bt] --EOF--\\n\")"))
command <- sprintf("%s %s", "Rscript", stringi::stri_flatten(args, " "))
command = shQuote(command)
# command <- stringi::stri_replace_all_fixed(command, "\\$", "$")
sys.args <- c("-q", "myremotehost", command)
sys.cmd <- "ssh"
res <- suppressWarnings(system2(command = sys.cmd, args = sys.args, stdin = "", 
   stdout = TRUE, stderr = TRUE, wait = TRUE))
output <- as.character(res)
output

[1] "[bt] --BOF--"                                                  
[2] "[bt] /usr/local/lib/R/site-library/batchtools/bin/linux-helper"
[3] "[bt] --EOF--"                                                  
[4] ""  
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

@franzbischoff
Copy link

And now I'm here again "solving" the same issue... I forgot I've already had...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants