From pd@|gd @end|ng |rom gm@||@com  Tue Mar 19 11:44:40 2019
From: pd@|gd @end|ng |rom gm@||@com (peter dalgaard)
Date: Tue, 19 Mar 2019 11:44:40 +0100
Subject: [Rd] Possibly broken system2 env-option
In-Reply-To: <CABtg=K=RUYOXkgUgMmMKxYcmDTm9ZUNt2bErKLrs9wiMx1B50w@mail.gmail.com>
References: <f38d1b55-c8f8-dbe4-94c4-bf15bb32c052@gmx.de>
 <3244E2B3-3E44-4469-919B-4E5768F06F23@gmail.com>
 <CABtg=K=RUYOXkgUgMmMKxYcmDTm9ZUNt2bErKLrs9wiMx1B50w@mail.gmail.com>
Message-ID: <A5278CAD-D8BD-45B2-A14C-709BDB8FFDB0@gmail.com>

     On Windows, ?env? is only supported for commands such as ?R? and
     ?make? which accept environment variables on their command line.

So I suppose that would be tricky. 

The basic issue is that on Unix-alikes, system2 constructs a command like

FOO=bar cmd args

and passes that to sh via system(). On windoes, system() does not call sh, so system2() does (effectively)

cmd FOO=bar args

and hopes that cmd knows what to do with the env setting.

-pd

> On 19 Mar 2019, at 11:09 , G?bor Cs?rdi <csardi.gabor at gmail.com> wrote:
> 
> On Tue, Mar 19, 2019 at 9:59 AM peter dalgaard <pdalgd at gmail.com> wrote:
> [...]
>> What you need is something like (NB: single quotes!)
>>> system2("sh", env = c("VAR='Hello World'"), args = c("-c 'echo $VAR'"))
>> Hello World
> 
> Just out of curiosity, do you think it is possible to make this
> portable, assuming sh is available? On Windows it gives
> 
>> system2("sh", env = c("VAR='Hello World'"), args = c("-c 'echo $VAR'"))
> /rtools34/bin/sh: VAR=Hello World: No such file or directory
> Warning message:
> running command '"sh" VAR='Hello World' -c 'echo $VAR'' had status 127
> 
> G.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Possibly broken system2 env-option
peter dalgaard