Dan Tenenbaum
2010-Nov-11 02:21 UTC
[Rd] Problem with system2(), directing STDERR to a file
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]]
Keith Satterley
2010-Nov-11 03:33 UTC
[Rd] Problem with system2(), directing STDERR to a file
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 intend...{{dropped:4}}
Possibly Parallel Threads
- system2 doesn't quote stdin on unix, unlike stdout, stderr & input and on Windows
- Capture output of install.packages (pipe system2)
- Redirect system2 stdout to a file on windows
- utils::install.packages with quiet=TRUE fails for source packages on Windows
- utils::install.packages with quiet=TRUE fails for source packages on Windows