System command fails in Shiny (similar topic as #11405)

I have moved the discussion to the original post and posted different tries with paste command: System call within R shiny

I am not sure if this is your problem, But this line should probably read

 system(paste("/bin/qt con ed -i", file_cf, "-p", file_ed, ">",  paste0(file_ed,".db") )

paste puts a space between the arguments while paste0 or paste(...., sep = ") does not.

A thing to try is to run the paste command and then run the output in a system terminal and see what happens.

This returns the same error as shown in question. And the output of paste command is also run in system terminal which is also shown in the initial question.

One thing to try is retype the system() line. I know it shouldn't make a difference, but sometimes it does in Rstudio.

One other thing would be to just run system ("/bin/qt") from the R prompt and see if that works. Then build on that until it breaks.

Debugging something like this is so much fun.

I have a similar issue running on Mac :

library(shiny)

ui <- fluidPage(
  fileInput("CF", label = "CF"),
  fileInput("ED", label = "ED"),
  actionButton("Run", "Run")
)


server <- function(input, output, session) {
    cf_file <- reactive({ 
        cfFile <- input$CF
        return(cfFile$datapath)
    })

    ed_file <- reactive({ 
        edFile <- input$ED
        return(edFile$datapath)
    })

    table_content <- eventReactive(input$Run, {
        req(input$ED$datapath)
        req(input$CF$datapath)
        file_ed <- ed_file()
        file_cf <- cf_file()
       system(paste("/bin/qt con ed -i", file_cf, "-p", file_ed, ">", file_ed,".db" ))
    })
}
shinyApp(ui, server)

Error:


sh: /bin/qt con ed -i /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/0a97a587dbd6a346e41946d1/0.cf -p /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/0925189f052a3cdc2163d025/0.ed > /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/0925189f052a3cdc2163d025/0.ed.db: No such file or directory
Warning in system2(paste("/bin/qt con ed -i",  :
  error in running command

When i run the command generated by the system command in normal shell (outside R) it works but fails within R.

/bin/qt con ed -i /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/0a97a587dbd6a346e41946d1/0.cf -p /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/0925189f052a3cdc2163d025/0.ed > /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/0925189f052a3cdc2163d025/0.ed.db

The issue is same with system and system2. Could someone help.

Your issue is likely because paste by default adds a space between the objects being pasted together. You should use paste0 instead and just put at the beginning and end of strings that need to have a space.

Hi,

It has been the same issue with both paste and paste0.

Have you tried to run the system call from inside R without the paste function? i.e. use the entire string that works in the shell from within the system call. If that works than you can narrow down that there is an issue with your paste call. If it doesn't than there is an issue with the system call.

Yes, the actual command with actual file paths works within R using system(). So it should be with paste command. So i tried different paste commands and the issue remains. Is there still something wrong in the paste commands?

Command1:
system2(paste0("/bin/qt con ed -i", file_cf, "-p", file_ed, ">", paste0(file_ed,".db" )))
Error:
sh: /bin/qt con ed -i/var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/9fd67e75a41ef125afaa6b4c/0.cf-p/var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/295c35dbcf002a71226c3b2a/0.phe>/var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/295c35dbcf002a71226c3b2a/0.ed.db: No such file or directory
Warning in system2(paste0("/bin/qt con ed -i",  :
  error in running command

Command2:
system2(paste("/bin/qt con ed -i", file_cf, "-p", file_ed, ">", paste(file_ed,".db" )))
Error:
sh: /bin/qt con ed -i /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/f5badfc377f905e9885b34c5/0.cf -p /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/80a2d18cba0ccda6b5b12a52/0.ed > /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/80a2d18cba0ccda6b5b12a52/0.ed .db: No such file or directory
Warning in system2(paste("/bin/qt con ed -i",  :
  error in running command

Command3:
system2(paste("/bin/qt con ed -i", file_cf, "-p", file_ed, ">", paste0(file_ed,".db" )))
Error:
sh: /bin/qt con ed -i /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/52d6a765a856c978802a72a3/0.cf -p /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/efba66487feb8303235be8c0/0.ed > /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//Rtmp7mxKnK/efba66487feb8303235be8c0/0.ed.db: No such file or directory
Warning in system2(paste("/bin/qt con ed -i",  :
  error in running command

This seems to work using system() instead system2():

system(paste("/bin/qt con ed -i",file_cf,"-p",file_ed,">",paste0(file_ed,".db" )))

And this command seems to write output to the tmp folders with tmp names. How could we write output to directories from which the input is read?

However, the command in the rstudio keeps still running i.e. not returning to the new command prompt. What does it mean?