Kernel.exec not behaving consistently on Windows?

Discussion in 'Ruby' started by Jarmo Pertman, Nov 27, 2010.

  1. Hello!

    It seems that Kernel.exec doesn't work consistently on Windows when
    compared with Kernel.system or IO.popen. Consider the following
    examples:

    This works:
    exec "ping", "localhost"

    This doesn't work:
    exec "ping.exe", "localhost"
    Errno::ENOENT: No such file or directory - ping.exe

    This works:
    exec "c:\\windows\\system32\\ping.exe", "localhost"

    This doesn't work:
    exec "c:\\windows\\system32\\ping", "localhost"
    Errno::ENOENT: No such file or directory - c:\windows\system32\ping

    When invoking exec always with only one parameter then all the
    examples above work correctly - e.g. with allowing Ruby to do the
    shell expansion which isn't changing for the examples above anything.
    Also, Windows shell doesn't do any expansion either since there isn't
    such a thing.

    Why is it like that? The problem is that Bundler uses
    "Kernel.exec(*ARGV)" which makes `bundle exec` to fail here and there
    (for example autotest within Rails3). What possible solution is there
    to fix that issue once and for all?

    I've opened a bug in Bundler's repo, which is now closed due no good
    solutions or just a matter of opinions that this bug is not Bundler's.
    Maybe this is a bug of Ruby instead and if it's not then should it be
    fixed within Bundler or within every other library. I'd bet for
    Bundler since that is one of the central places which every other
    library might use, even if the bug is Ruby's.

    And if that all is expected behavior then what should be the solution.

    By the way, all examples above seem to be working fine on 1.9 MRI, but
    fail on 1.8 MRI.

    Jarmo Pertman
    -----
    IT does really matter - http://www.itreallymatters.net
     
    Jarmo Pertman, Nov 27, 2010
    #1
    1. Advertising

  2. Jarmo Pertman, Nov 27, 2010
    #2
    1. Advertising

  3. Jarmo Pertman

    Luis Lavena Guest

    On Nov 27, 6:07 pm, Jarmo Pertman <> wrote:
    > Hello!
    >
    > It seems that Kernel.exec doesn't work consistently on Windows when
    > compared with Kernel.system or IO.popen. Consider the following
    > examples:
    >
    > This works:
    > exec "ping", "localhost"
    >
    > This doesn't work:
    > exec "ping.exe", "localhost"
    > Errno::ENOENT: No such file or directory - ping.exe
    >
    > This works:
    > exec "c:\\windows\\system32\\ping.exe", "localhost"
    >
    > This doesn't work:
    > exec "c:\\windows\\system32\\ping", "localhost"
    > Errno::ENOENT: No such file or directory - c:\windows\system32\ping
    >
    > By the way, all examples above seem to be working fine on 1.9 MRI, but
    > fail on 1.8 MRI.
    >


    Ruby 1.8.x Kernel#exec is broken. The changes required to fix this
    were so radical that couldn't be backported from 1.9.x to 1.8.x

    Rake for example workaround this:

    https://github.com/jimweirich/rake/blob/master/lib/rake/alt_system.rb

    --
    Luis Lavena
     
    Luis Lavena, Nov 27, 2010
    #3
  4. But Rake only handles system and backticks - is the problem same with
    exec?

    Jarmo

    On Nov 27, 11:51 pm, Luis Lavena <> wrote:
    > Ruby 1.8.x Kernel#exec is broken. The changes required to fix this
    > were so radical that couldn't be backported from 1.9.x to 1.8.x
    >
    > Rake for example workaround this:
    >
    > https://github.com/jimweirich/rake/blob/master/lib/rake/alt_system.rb
    >
    > --
    > Luis Lavena
     
    Jarmo Pertman, Nov 27, 2010
    #4
    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. Replies:
    2
    Views:
    541
  2. yogesh
    Replies:
    3
    Views:
    601
    Kenny McCormack
    Feb 12, 2006
  3. Replies:
    3
    Views:
    182
  4. Lars Gierth
    Replies:
    6
    Views:
    237
    David Masover
    Mar 20, 2010
  5. Joe Kehnast
    Replies:
    3
    Views:
    126
    Grant Wagner
    Jun 17, 2004
Loading...

Share This Page