How to use the system command on windows correctly

Hello,

I have windows 10 64bits and R version 3.5.2 (2018-12-20),
i try to do this command

shell_path <- "C:/Users/user/cmder/vendor/git-for-windows/git-bash.exe" 
shell("ls", shell = shell_path, minimized=F)

A windows is opened with the tittle: /usr/bin/bash --login -i /c ls and i get this message:

Creating user startup file: /config/user_profile.sh
cp: cannot stat '/vendor/user_profile.sh.default': No such file or directory
bash: /c: Is a directory
/usr/bin/bash: Exit 126.

I got the wrong folder, you had to go to in "C:/Users/user/cmder/vendor/git-for-windows/bin/bash.exe"

If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.

Thanks

Hello,

sorry, I was waiting because I had another problem with the shell() command.

When i do the command ls it's work, but when I use another command it doesn't work.

> shell('echo "something"', shell = shell_path)
# get a blank line
> shell("ls", pathShell)
rep1
rep2
> shell("cd rep1; ls", pathShell) # it's return nothing
> 

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

Hello, thank for the links,

I use reprex but I don't have a return when I use the shell() function. It doesn't display the result as in the link you gave me. I put in comment the return I get when I use the commands in the console.

shell_path <- "C:/Users/user/cmder/vendor/git-for-windows/bin/bash.exe"
shell(cmd = "ls", shell = shell_path) # 1
shell(cmd = 'echo "something"', shell = shell_path) # 2
shell(cmd = "ls rep1", shell = shell_path) # 3
# ---

devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.2 (2018-12-20)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  French_France.1252          
#>  ctype    French_France.1252          
#>  tz       Indian/Mauritius            
#>  date     2019-06-18                  
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.5.3)
#>  backports     1.1.4   2019-04-10 [1] CRAN (R 3.5.3)
#>  callr         3.2.0   2019-03-15 [1] CRAN (R 3.5.3)
#>  cli           1.1.0   2019-03-19 [1] CRAN (R 3.5.3)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.3)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.5.2)
#>  devtools      2.0.2   2019-04-08 [1] CRAN (R 3.5.3)
#>  digest        0.6.18  2018-10-10 [1] CRAN (R 3.5.3)
#>  evaluate      0.13    2019-02-12 [1] CRAN (R 3.5.2)
#>  fs            1.3.1   2019-05-06 [1] CRAN (R 3.5.3)
#>  glue          1.3.1   2019-03-12 [1] CRAN (R 3.5.3)
#>  highr         0.8     2019-03-20 [1] CRAN (R 3.5.3)
#>  htmltools     0.3.6   2017-04-28 [1] CRAN (R 3.5.2)
#>  knitr         1.23    2019-05-18 [1] CRAN (R 3.5.3)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 3.5.2)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.5.2)
#>  pkgbuild      1.0.3   2019-03-20 [1] CRAN (R 3.5.3)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.5.2)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.5.2)
#>  processx      3.3.1   2019-05-08 [1] CRAN (R 3.5.3)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.5.2)
#>  R6            2.4.0   2019-02-14 [1] CRAN (R 3.5.2)
#>  Rcpp          1.0.1   2019-03-17 [1] CRAN (R 3.5.3)
#>  remotes       2.0.4   2019-04-10 [1] CRAN (R 3.5.3)
#>  rlang         0.3.4   2019-04-07 [1] CRAN (R 3.5.3)
#>  rmarkdown     1.12    2019-03-14 [1] CRAN (R 3.5.3)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.5.2)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.2)
#>  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.5.3)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.5.3)
#>  testthat      2.1.1   2019-04-23 [1] CRAN (R 3.5.3)
#>  usethis       1.5.0   2019-04-07 [1] CRAN (R 3.5.3)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.2)
#>  xfun          0.7     2019-05-14 [1] CRAN (R 3.5.3)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.5.2)
#> 
#> [1] C:/Users/user/Documents/R/win-library/3.5
#> [2] C:/Program Files/R/R-3.5.2/library

# Return I get when I use the commands in the console:

#1 
# return
# rep1
# rep2
# reprex_shell.R

#2
# return a blank line

# 3
# return
# rep1
# rep2
# reprex_shell.R

Created on 2019-06-18 by the reprex package (v0.3.0)

Hello,

Apparently the problem came from a bad writing of the path, you had to use the "\\" as separator and to write the command I used the shQuote() function

path <- 'C:\\Users\\user\\cmder\\vendor\\git-for-windows\\bin\\bash.exe'
cmd <- shQuote("echo hello", type="sh")
shell(cmd = cmd, shell = path)
hello

Thank for your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.