From simon.urbanek at r-project.org  Wed Oct  5 16:45:46 2011
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Wed, 5 Oct 2011 10:45:46 -0400
Subject: [Rd] suppressing stderr output from system() calls
In-Reply-To: <972B666A-E4F0-4479-9C45-13428A5AD0B7@garvan.org.au>
References: <972B666A-E4F0-4479-9C45-13428A5AD0B7@garvan.org.au>
Message-ID: <6F876B33-09D6-4E9B-9DBA-C2A648A32F8C@r-project.org>

See ?system, in particular ignore.stdout, ignore.stderr and intern.

Cheers,
Simon


On Oct 5, 2011, at 5:36 AM, Mark Cowley wrote:

> Dear list,
> I'm trying to suppress/redirect/squash the output from commands like install.packages, or download.file. The problem is that none of: sink(..., type="message"), sink(..., type="output"), capture.output, suppressMessages are quite doing the trick. Output gets written to the stderr stream, despite any combination of the above suppression commands.
> According to ?sink:
> Messages sent to ?stderr()? (including those from ?message?, ?warning? and ?stop?) can be diverted by ?sink(type = "message")? (see below).
> 
> I'm pretty sure it's the system(), or .Internal() calls which are the culprit, which currently write the majority (all?) of their output to the stderr stream.
> 
> Simple example:
> con <- file("stderr.txt", "w")
> sink(con, type="message")
> system("ls")
> sink(NULL, type="message")
> close(con)
> # instead of the output going to stderr.txt, it gets printed to the console.
> 
> # no good either
> capture.output(system("ls"))
> character(0)
> 
> This is an issue, since i'm writing GenePattern modules to run R code, and if anything is written to stderr, then the job gets hit with a 'job failed' status, when all that might have happened is an R package got installed, or a file got downloaded via FTP.
> 
> Any ideas? Can system() and .Internal() output be redirected to stdout?
> 
> cheers,
> Mark
> 
> 
> sessionInfo()
> R version 2.13.1 (2011-07-08)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
> 
> locale:
> [1] en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base     
>> 
> 
> 
> 
> -----------------------------------------------------
> Mark Cowley, PhD
> 
> Pancreatic Cancer Program | Peter Wills Bioinformatics Centre
> Garvan Institute of Medical Research, Sydney, Australia
> -----------------------------------------------------
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] suppressing stderr output from system() calls
Simon Urbanek