From c@@rd|@g@bor @end|ng |rom gm@||@com  Tue Mar 19 10:48:16 2019
From: c@@rd|@g@bor @end|ng |rom gm@||@com (=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=)
Date: Tue, 19 Mar 2019 09:48:16 +0000
Subject: [Rd] Possibly broken system2 env-option
In-Reply-To: <f38d1b55-c8f8-dbe4-94c4-bf15bb32c052@gmx.de>
References: <f38d1b55-c8f8-dbe4-94c4-bf15bb32c052@gmx.de>
Message-ID: <CABtg=KkHmtMK5hLGJe52fyQkMe7tYN3Jj8KivPMdopQp4MyLJQ@mail.gmail.com>

Probably not broken, just hard to get the quoting right? Or it does
not work with echo?

It is surely hard to get it right, I have been trying for 15 minutes.I
am pretty sure that the correct form is env = "VAR='Hello-World'" but
spaces and other special characters might cause trouble. E.g. this
works, but only without spaces (px is an internal tool for testing,
that can get an env var, and it is portable):

? px <- processx:::get_tool("px")
? system2(px, c("getenv", "VAR"), env = "VAR=foo")
foo

? system2(px, c("getenv", "VAR"), env = c(VAR="Hello World"))
sh: Hello: command not found
Warning message:
In system2(px, c("getenv", "VAR"), env = c(VAR = "Hello World")) :
  error in running command

Somebody with more system2() experience can probably fix this, but
here is an alternative, using the processx package:

? processx::run(px, c("getenv", "VAR"), env = c(Sys.getenv(), VAR =
"Hello World"))
$status
[1] 0

$stdout
[1] "Hello World\n"

$stderr
[1] ""

$timeout
[1] FALSE

For processx, you don't need to quote anything (i.e. command,
arguments or env vars), because it does not
use an intermediate shell.

Disclaimer: I am an author of processx.

Gabor

On Tue, Mar 19, 2019 at 9:28 AM Henning Bredel <h.bredel at gmx.de> wrote:
>
> Hey all,
>
> what is wrong with this command:
>
>   system2("echo", env = c(VAR = "Hello World"), args = c("$VAR"))
>
> I am a bit confused, as help("system2") writes about the env option:
>
> > character vector of name=value strings to set environment variables.
>
> Is this option buggy, or am I using it just wrong?
>
> Thanks for your help
>
>   Henning
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Possibly broken system2 env-option
=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=