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

Discussion in 'Ruby' started by Wes Gamble, Sep 23, 2007.

  1. Wes Gamble

    Wes Gamble Guest

    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-forum.com/.
    Wes Gamble, Sep 23, 2007
    #1
    1. Advertising

  2. 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-forum.com/.
    Wolfgang Nádasi-Donner, Sep 23, 2007
    #2
    1. Advertising

  3. Wes Gamble

    Wes Gamble Guest

    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-forum.com/.
    Wes Gamble, Sep 23, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,065
    Peter Otten
    Jun 3, 2005
  2. Sarir Khamsi

    Interpreter-like help in cmd.Cmd

    Sarir Khamsi, Jun 9, 2005, in forum: Python
    Replies:
    4
    Views:
    369
    Bengt Richter
    Jun 26, 2005
  3. =?ISO-8859-1?Q?Sch=FCle_Daniel?=

    [exec cmd for cmd in cmds]

    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Mar 8, 2006, in forum: Python
    Replies:
    3
    Views:
    387
    Scott David Daniels
    Mar 8, 2006
  4. Diez B. Roggisch

    pydb remote debugging/cmd.Cmd over socket?

    Diez B. Roggisch, May 28, 2008, in forum: Python
    Replies:
    2
    Views:
    548
    Diez B. Roggisch
    May 29, 2008
  5. Diez B. Roggisch

    cmd.Cmd bug or at least docu-bug

    Diez B. Roggisch, May 29, 2008, in forum: Python
    Replies:
    1
    Views:
    342
    Michele Simionato
    May 29, 2008
Loading...

Share This Page