Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2398
| From | Angelo NN <storm8000@gmail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Windows 2008 Server: Reading Text File with Ruby. |
| Date | 2011-04-06 14:30 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <3a5099f0e260e4856cd4d6e9c9f09223@ruby-forum.com> (permalink) |
Hello -
New Ruby user here.
I was wondering if you could point me in the right direction:
- I save the output of a WMIC query to a temp text file on Windows 2008
using Ruby:
system("wmic MEMORYCHIP get CAPACITY /VALUE > tmp")
- Next, I try to read this file back in order to extract a value from
the output:
contents = File.open('tmp', 'r:') { |f| f.read }
However, when I run this in irb, the file is imported with the following
leading characters: \x00 and others. If I open the actual tmp file in
Windows, it displays the correct text.
Is there a way to just import that text only? Is this something to do
with encoding?
Thank you for your help.
Here is the entire session in irb:
irb(main):002:0> system("wmic MEMORYCHIP get CAPACITY /VALUE >
tmp")
=> true
irb(main):003:0> contents = File.open('tmp', 'r:') { |f| f.read }
=>
"\xFF\xFE\n\x00\n\x00N\x00o\x00d\x00e\x00,\x00C\x00a\x00p\x00a\x00c\x00i\x00t
\x00y\x00\n\x00\n\x00P\x00S\x00,\x008\x005\x008\x009\x009\x003\x004\x005\x009\x0
02\x00"
irb(main):004:0>
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Windows 2008 Server: Reading Text File with Ruby. Angelo NN <storm8000@gmail.com> - 2011-04-06 14:30 -0500
Re: Windows 2008 Server: Reading Text File with Ruby. Jonathan Hudson <jh_ruby-lang@daria.co.uk> - 2011-04-06 14:33 -0500
Re: Windows 2008 Server: Reading Text File with Ruby. Angelo NN <storm8000@gmail.com> - 2011-04-06 14:35 -0500
Re: Windows 2008 Server: Reading Text File with Ruby. Jonathan Hudson <jh_ruby-lang@daria.co.uk> - 2011-04-06 14:47 -0500
Re: Windows 2008 Server: Reading Text File with Ruby. Angelo NN <storm8000@gmail.com> - 2011-04-06 14:58 -0500
Re: Windows 2008 Server: Reading Text File with Ruby. Jonathan Hudson <jh_ruby-lang@daria.co.uk> - 2011-04-06 15:12 -0500
Re: Windows 2008 Server: Reading Text File with Ruby. Angelo NN <storm8000@gmail.com> - 2011-04-06 15:15 -0500
Re: Windows 2008 Server: Reading Text File with Ruby. "F. Senault" <fred@lacave.net> - 2011-04-06 22:45 +0200
csiph-web