Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Does open("| #{cmd}", "r") work in Windows?
Wes Gamble
9/23/2007 5:23:00 PM
All,
Attempting to debug the autotest gem on Windows. I've gotten as far as
discovering that in the code below, the open call will succeed (and cmd
has a real command in it), however the file object f, will be at eof
immediately.
I can run this command on the command line in Windows and see that it
has output.
My questions is:
should I expect open("| <whatever>", "r") to run the command and then
get the output in the attached block on Windows?
open("| #{cmd}", "r") do |f|
until f.eof? do
c = f.getc
putc c
line << c
if c == ?\n then
@results << line.pack("c*")
line.clear
end
end
end
Thanks,
Wes
--
Posted via
http://www.ruby-...
.
2 Answers
Wolfgang Nádasi-donner
9/23/2007 8:18:00 PM
0
Wes Gamble wrote:
> should I expect open("| <whatever>", "r") to run the command and then
> get the output in the attached block on Windows?
I tested the following under Windows2000...
>>>>> Example >>>>>
C:\Dokumente und Einstellungen\wolfgang>time
Aktuelle Zeit: 22:14:57,53
Geben Sie die neue Zeit ein:
C:\Dokumente und Einstellungen\wolfgang>irb
irb(main):001:0> open('|time', 'a+') do |f|
irb(main):002:1* old = f.gets.chomp
irb(main):003:1> f.write '11'
irb(main):004:1> puts "old: #{old}"
irb(main):005:1> end
old: Aktuelle Zeit: 22:15:12,21
=> nil
irb(main):006:0> exit
C:\Dokumente und Einstellungen\wolfgang>time
Aktuelle Zeit: 11:00:12,28
Geben Sie die neue Zeit ein:
>>>>> EoE >>>>>
...and it works.
Wolfgang Nádasi-Donner
--
Posted via
http://www.ruby-...
.
Wes Gamble
9/23/2007 8:55:00 PM
0
It turns out that my problem is that the command being passed to
Kernel.open is in the form
C:\ruby\bin\ruby ...
Because the command is enclosed in double quotes ("), the \r is being
interpreted as a special character and the path is not understood
correctly.
If you:
1) replace the double quotes with single quotes, or
2) leave the double quotes and escape the backslashes in the path, or
3) replace the backslashes with forward slashes,
it will work.
I'll look into submitting a patch for ZenTest so that the calling code
will work.
Wes
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Does open("| #{cmd}", "r") work in Windows?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password