Re: [Rd] Problem with system2(), directing STDERR to a file

From: Dan Tenenbaum <dtenenba_at_fhcrc.org>
Date: Thu, 11 Nov 2010 20:44:55 -0800

I notice that a fix for this issue was checked in. Thanks, much appreciated!

But it still seems broken on Windows. Given the same ruby script, and this R code:

> cmd <- "c:/ruby192/bin/ruby"
> args <- c("test.rb")
> t <- tempfile()
> system2(cmd, args, stdout=TRUE, stderr=t)
[1] "stderr" "stdout"
> file.exists(t)

[1] FALSE I would expect only "stdout" to show up in the console, and t to contain "stderr".

> sessionInfo()

R version 2.13.0 Under development (unstable) (2010-11-04 r53530) Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:

[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

loaded via a namespace (and not attached): [1] tools_2.13.0

Thanks
Dan

On Wed, Nov 10, 2010 at 9:11 PM, Dan Tenenbaum <dtenenba_at_fhcrc.org> wrote:

> Hi Keith,
>
> The problem is not with tempfile(), and is not really a problem of whether
> a file exists or not. The problem is that system2() does not put the
> contents of stderr into the file. Here is a demonstration without the use of
> tempfile(), using a pre-existing output file:
>
> klediment:~ dante$ echo "Hello" > output.txt
> klediment:~ dante$ cat output.txt
> Hello
> klediment:~ dante$ R -q
> > system2("./test.rb", stderr="output.txt")
> stderrstdout> q("no") # should only see "stdout" in console, "stderr"
> should go to file
> klediment:~ dante$ cat output.txt
> Hello
> klediment:~ dante$ R -q
> > system2("./test.rb", stdout="output.txt") # works correctly
> stderr> q("no")
> klediment:~ dante$ cat output.txt
> stdoutklediment:~ dante$
>
> My sessionInfo() follows, but I got the identical behavior on R 2.12
> (release version) and R 2.13.
>
> Thanks,
> Dan
>
>
> > sessionInfo()
> R version 2.12.0 Patched (2010-10-15 r53335)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
>
>
> On Wed, Nov 10, 2010 at 7:33 PM, Keith Satterley <keith_at_wehi.edu.au>wrote:
>
>> Looking at help for tempfile,
>>
>> "tempfile" returns a vector of character strings which can be used as
>> names for temporary files.
>>
>> and
>>
>> For "tempfile" a character vector giving the names of possible
>> (temporary) files. Note that no files are generated by "tempfile".
>>
>>
>> try a file.create(t) after tempfile()
>>
>> cheers,
>>
>> Keith
>>
>>
>> Dan Tenenbaum wrote:
>>
>>> According to ?system2, I should be able to direct the output of STDERR to
>>> a
>>> file by giving the filename as a character vector to the "stderr"
>>> argument.
>>>
>>> But here is what happens.
>>>
>>> Given a ruby script test.rb (with its executable bit set):
>>>
>>> #!/usr/bin/env ruby
>>> STDOUT.puts "stdout"
>>> STDERR.puts "stderr"
>>>
>>> And the following R code:
>>>
>>>
>>>
>>>> t <- tempfile()
>>>> res <- system2("./test.rb", stdout=TRUE, stderr=t)
>>>>
>>>>
>>> stderr
>>>
>>>
>>>> res
>>>>
>>>>
>>> [1] "stdout"
>>>
>>>
>>>> file.exists(t)
>>>>
>>>>
>>> [1] FALSE
>>>
>>> I would expect the file t to exist and contain "stderr", and I would
>>> expect
>>> not to see "stderr" in the console.
>>>
>>> Also, there is a typo in the man page - the command is listed as "system"
>>> in
>>> the Description instead of "system2".
>>>
>>> The reverse behavior does work correctly:
>>>
>>>
>>>> res <- system2("./test.rb", stdout=t, stderr="")
>>>>
>>>>
>>> stderr
>>>
>>>
>>>> file.exists(t)
>>>>
>>>>
>>> [1] TRUE
>>>
>>>
>>> Thanks!
>>> Dan
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-devel_at_r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>>
>> ______________________________________________________________________
>> The information in this email is confidential and intended solely for the
>> addressee.
>> You must not disclose, forward, print or use it without the permission of
>> the sender.
>> ______________________________________________________________________
>>
>>
>

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 12 Nov 2010 - 04:53:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 12 Nov 2010 - 21:40:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive