That is what I thought for a while too, but in this case you can have your cake and eat it too, at least with stderr. :) Windows lets you redirect STDERR to STDOUT, so you can use that when executing commands within Ruby.
For example, when running nslookup and failing to resolve a host, part of the output can be missing from the returned string, since some goes to STDERR: irb(main):009:0* `nslookup fakehost` *** foo.com can't find fakehost: Non-existent domain => "Server: foo.com\nAddress: xxx.xxx.xxx.xxx\n\n" Instead you can redirect STDERR to STDOUT and get all of the output of that command, by appending 2>&1 to the command string: irb(main):010:0> `nslookup fakehost 2>&1` => "*** foo.com can't find fakehost: Non-existent domain\r\ nServer: foo.com\nAddress: 192.168.157.200\n\n" More info is here: http://support.microsoft.com/kb/110930 Thanks Bill On Tue, Mar 3, 2009 at 1:14 PM, Andy Sipe <[email protected]> wrote: > One caveat to this is that you only get stdout using the backtick. You > don't get the other streams (stderr, etc..). At least this is my > experience on windows. > > -andy > > On Tue, Mar 3, 2009 at 4:05 PM, Bill Agee <[email protected]> wrote: > >> To get the standard output of a command, you can enclose it in backticks, >> like in Perl - see the related rdoc: >> >> http://www.ruby-doc.org/core/classes/Kernel.html#M006001 >> >> Note that by default you'll get back one big string when you run the >> command. But it sounds like you are looking to get an array in which each >> line of output is in a separate element. To do that, just split the string >> on newlines: >> >> myarray = `dir`.split(/\n/) >> >> Thanks >> Bill >> - Show quoted text - >> >> >> >> On Tue, Mar 3, 2009 at 6:01 AM, venky <[email protected]> wrote: >> >>> >>> Hi All, >>> >>> I am using system("dir") to execute commands in Command Prompt. >>> >>> I get the result(below) when I execute system("dir") command. I need >>> to store the result in an array. >>> I tried arr = system("dir") which stores true or false. Please throw >>> some light on this >>> >>> Result: >>> =================================== >>> Volume in drive E has no label. >>> Volume Serial Number is 603F-F8C6 >>> >>> Directory of E:\Temp >>> >>> 02/27/2009 07:05 PM <DIR> . >>> 02/27/2009 07:05 PM <DIR> .. >>> 03/03/2009 07:11 PM 65 t.rb >>> 02/27/2009 06:22 PM 3,251 temp.rb >>> 02/27/2009 07:05 PM 1,011 temp2.rb >>> 3 File(s) 4,327 bytes >>> 2 Dir(s) 22,208,159,744 bytes free >>> ===================================== >>> >>> Thanks, >>> Venkat >>> >>> >>> >>> >>> >> >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to [email protected] Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/watir-general -~----------~----~----~----~------~----~------~--~---
