Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > capturing stderr for a file

Reply
Thread Tools

capturing stderr for a file

 
 
Ted Flethuseo
Guest
Posts: n/a
 
      02-17-2011
Hi everyone,

I am trying to run a script from ruby, but it produces some output to
STDERR. It isn't capturing that output. How do I capture it?

file = File.open("my.txt", "w")

arr.each do |e|
file.puts `./script.sh #{e}`
end

Ted.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Avdi Grimm
Guest
Posts: n/a
 
      02-17-2011
On Wed, Feb 16, 2011 at 7:04 PM, Ted Flethuseo <(E-Mail Removed)> wrote:
> I am trying to run a script from ruby, but it produces some output to
> STDERR. It isn't capturing that output. How do I capture it?


Two options:

1. Redirect STDOUT to STDERR in the command:

output = `./script.sh #{e} 2>&1`

2. Use Open3 to capture the error stream:

require 'open3'
Open3.popen3("./script.sh #{e} 2>&1") do |i, o, e|
puts "STDOUT: #{o.read}"
puts "STDERR: #{e.read}"
end

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
capturing stdout and stderr? Mike Perl Misc 0 08-09-2009 09:33 PM
Capturing stderr and stdout of a subprocess as a single stream Fuzzyman Python 3 01-07-2007 08:44 PM
Capturing stderr from Kernel.exec Carl Lerche Ruby 2 09-09-2006 04:01 AM
Capturing output from stderr Doru-Catalin Togea Python 2 12-05-2005 01:36 PM
capturing stderr from windows Brian Perl Misc 4 04-22-2004 07:11 AM



Advertisments