Does open("| #{cmd}", "r") work in Windows?

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("| ", “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

Wes G. wrote:

should I expect open("| ", “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

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