Executing systems commands

Discussion in 'Ruby' started by John Maclean, Apr 24, 2008.

  1. John Maclean

    John Maclean Guest

    =begin
    Hey chaps.

    I'm using an array to find the locations of various commands on a
    system. Three versions of the same thing. Two work and one doesn't. Any one
    know why?
    =end

    # here's an array of commands that we want to find
    k = %w[ ruby xterm enlightenment emacs]


    #why does this work?
    k.each do |x|
    p system("which #{x}")
    end

    # and this work
    k.each do |x|
    p system("whereis #{x}")
    end


    # but this doesn't
    k.each do |x|
    p system("type -p #{x}")
    end


    __END__
    Regards,

    - jjm
     
    John Maclean, Apr 24, 2008
    #1
    1. Advertising

  2. John Maclean

    Guest

    John Maclean ha scritto:

    > =begin
    > Hey chaps.
    >
    > I'm using an array to find the locations of various commands on a
    > system. Three versions of the same thing. Two work and one doesn't. Any one
    > know why?
    > =end
    >
    > # here's an array of commands that we want to find
    > k = %w[ ruby xterm enlightenment emacs]
    >
    >
    > #why does this work?
    > k.each do |x|
    > p system("which #{x}")
    > end
    >
    > # and this work
    > k.each do |x|
    > p system("whereis #{x}")
    > end
    >
    >
    > # but this doesn't
    > k.each do |x|
    > p system("type -p #{x}")
    > end
    >
    >
    > __END__
    > Regards,
    >


    Just a hint (maybe wrong): could this depend on the fact that "type"
    is a
    shell builtin, while "which" and "whereis" are external commands?
     
    , Apr 24, 2008
    #2
    1. Advertising

  3. * John Maclean <> (12:19) schrieb:

    > #why does this work?
    > k.each do |x|
    > p system("which #{x}")
    > end
    >
    > # and this work
    > k.each do |x|
    > p system("whereis #{x}")
    > end


    which and whereis are real programs

    > # but this doesn't
    > k.each do |x|
    > p system("type -p #{x}")
    > end


    whereas type is a shell builtin. On my system the standard shell is dash,
    which doesn't recognize the -p switch.

    NB: system just returns true or false, the output of the command is not
    passed to ruby. Use %x for that.

    mfg, simon .... l
     
    Simon Krahnke, Apr 24, 2008
    #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. Mitchley
    Replies:
    0
    Views:
    617
    Mitchley
    Jun 10, 2004
  2. Mike
    Replies:
    2
    Views:
    633
  3. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,974
    Thomas Stegen
    Jun 28, 2003
  4. Tim Stanka
    Replies:
    1
    Views:
    804
    Jeff Epler
    Aug 2, 2004
  5. Cyde Weys
    Replies:
    14
    Views:
    189
    gnari
    Feb 26, 2004
Loading...

Share This Page