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

bash -c #36

Open
nick-youngblut opened this issue Feb 12, 2021 · 5 comments
Open

bash -c #36

nick-youngblut opened this issue Feb 12, 2021 · 5 comments

Comments

@nick-youngblut
Copy link

In order to activate a conda env prior to running the system command, I'm using bash -c ". ~/.bashrc; conda activate MY_CONDA_ENV; MY ACTUAL COMMAND"

This works with system2(), but with exec_wait('bash', cmd), I get:

bash -c "ls -thlc"
bash: - : invalid option
Usage:	bash [GNU long option] [option] ...
	bash [GNU long option] [option] script-file ...
GNU long options:
	--debug
	--debugger
	--dump-po-strings
	--dump-strings
	--help
	--init-file
	--login
	--noediting
	--noprofile
	--norc
	--posix
	--rcfile
	--restricted
	--verbose
	--version
Shell options:
	-ilrsD or -c command or -O shopt_option		(invocation only)
	-abefhkmnptuvxBCHP or -o option

My sessionInfo:

R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /opt/R/3.6.2/lib/R/lib/libRblas.so
LAPACK: /opt/R/3.6.2/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sys_3.4           LeyLabRMisc_0.1.7 tidytable_0.5.7   tidyselect_1.1.0  data.table_1.13.6

loaded via a namespace (and not attached):
 [1] rstudioapi_0.13  magrittr_1.5     pkgload_1.0.2    R6_2.4.1         rlang_0.4.7      fansi_0.4.0      tools_3.6.2      cli_2.0.0        withr_2.1.2     
[10] assertthat_0.2.1 rprojroot_1.3-2  tibble_2.1.3     lifecycle_0.2.0  crayon_1.3.4     purrr_0.3.3      vctrs_0.3.6      testthat_2.3.1   glue_1.4.1      
[19] compiler_3.6.2   pillar_1.4.3     desc_1.2.0       backports_1.1.5  renv_0.9.2       pkgconfig_2.0.3
@jeroen
Copy link
Owner

jeroen commented Feb 12, 2021

You need to split the command line args into a vector like so if I read your command correctly

cmd <- c("-c", ".", ". ~/.bashrc")
exec_wait("bash", cmd)

@nick-youngblut
Copy link
Author

I'm getting the following:

> cmd <- c("-c", ".", "ls -thlc")
> exec_wait("bash", cmd)
ls -thlc: line 0: .: filename argument required
.: usage: . filename [arguments]

> cmd <- c("-c", ".", ". ~/.bashrc")
> exec_wait("bash", cmd)
. ~/.bashrc: line 0: .: filename argument required
.: usage: . filename [arguments]
[1] 2

> cmd <- c("-c", ".", "~/.bashrc; conda activate base; conda list")
> exec_wait("bash", cmd)
~/.bashrc; conda activate base; conda list: line 0: .: filename argument required
.: usage: . filename [arguments]
[1] 2

@jeroen
Copy link
Owner

jeroen commented Feb 12, 2021

You need to split your "ls -thlc" as well, otherwise it is interpreted as a single program. Just strsplit() everything by space :)

@nick-youngblut
Copy link
Author

There's no change:

> cmd <- c("-c", ".", "ls", "-thlc")
> exec_wait("bash", cmd)
ls: line 0: .: filename argument required
.: usage: . filename [arguments]

To be clear, the goal is to run 3 commands via exec_wait(), as stated above (eg., bash -c "~/.bashrc; conda activate base; conda list")

@nick-youngblut
Copy link
Author

So is it possible to include multiple commands via exec_wait() with either bash -c "~/.bashrc; conda activate base; conda list" or . ~/.bashrc && conda activate base && conda list?

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