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

W

Wes Gamble

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
 
W

Wolfgang Nádasi-Donner

Wes said:
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...
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:
...and it works.

Wolfgang Nádasi-Donner
 
W

Wes Gamble

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top