run a command on shell with ruby

Discussion in 'Ruby' started by Corpus Callosum, May 19, 2007.

  1. hi guys,

    i want to run a command with a ruby programme. for example, assume that
    i have a ruby script and when run its, it make "apt-get install gaim"
    command run..

    what is the method or way of that ?
    thanks

    --
    Posted via http://www.ruby-forum.com/.
    Corpus Callosum, May 19, 2007
    #1
    1. Advertising

  2. ok i got it. and i am giving an example for who want to know

    #! /usr/bin/ruby
    exec "apt-get install gaim";

    this script run that command on shell


    Corpus Callosum wrote:
    > hi guys,
    >
    > i want to run a command with a ruby programme. for example, assume that
    > i have a ruby script and when run its, it make "apt-get install gaim"
    > command run..
    >
    > what is the method or way of that ?
    > thanks



    --
    Posted via http://www.ruby-forum.com/.
    Corpus Callosum, May 19, 2007
    #2
    1. Advertising

  3. Corpus Callosum

    Tim Pease Guest

    On 5/19/07, Corpus Callosum <> wrote:
    > hi guys,
    >
    > i want to run a command with a ruby programme. for example, assume that
    > i have a ruby script and when run its, it make "apt-get install gaim"
    > command run..
    >
    > what is the method or way of that ?
    > thanks
    >


    system "apt-get install gaim"

    I'd recommend using pidgin -- it's the newest release of gaim.

    http://www.pidgin.im/

    TwP
    Tim Pease, May 19, 2007
    #3
  4. Corpus Callosum

    Tim Hunter Guest

    Corpus Callosum wrote:
    > hi guys,
    >
    > i want to run a command with a ruby programme. for example, assume that
    > i have a ruby script and when run its, it make "apt-get install gaim"
    > command run..
    >
    > what is the method or way of that ?
    > thanks
    >
    >

    Use the Kernel#system method, or surround the command with backticks.

    system("apt-get install gaim")
    `apt-get install gaim`

    --
    RMagick [http://rmagick.rubyforge.org]
    RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]
    Tim Hunter, May 19, 2007
    #4
  5. On 5/19/07, Corpus Callosum <> wrote:
    > hi guys,
    >
    > i want to run a command with a ruby programme. for example, assume that
    > i have a ruby script and when run its, it make "apt-get install gaim"
    > command run..
    >
    > what is the method or way of that ?
    > thanks


    system?
    http://www.ruby-doc.org/core/classes/Kernel.html#M005960

    --
    Felipe Contreras
    Felipe Contreras, May 19, 2007
    #5
  6. Corpus Callosum

    Gian Holland Guest

    Web search api's?

    Hey guys are there any web search api's that are ruby friendly?
    Gian Holland, May 19, 2007
    #6
  7. Re: Web search api's?

    On May 19, 5:21 pm, Gian Holland <> wrote:
    > Hey guys are there any web search api's that are ruby friendly?


    Please do not thread-hijack. You should create a new message rather
    than changing the subject line unless the new subject has something to
    do with the original discussion.
    Gregory Brown, May 20, 2007
    #7
  8. Corpus Callosum

    Gian Holland Guest

    Re: Web search api's?

    My apologies it was done inadvertently.

    Gregory Brown wrote:
    > On May 19, 5:21 pm, Gian Holland <> wrote:
    >
    >> Hey guys are there any web search api's that are ruby friendly?
    >>

    >
    > Please do not thread-hijack. You should create a new message rather
    > than changing the subject line unless the new subject has something to
    > do with the original discussion.
    >
    >
    >
    >
    Gian Holland, May 20, 2007
    #8
  9. Corpus Callosum

    Axel Etzold Guest

    Axel Etzold, May 20, 2007
    #9
  10. Corpus Callosum

    ara.t.howard Guest

    On May 19, 2007, at 2:23 PM, Corpus Callosum wrote:

    >
    > ok i got it. and i am giving an example for who want to know
    >
    > #! /usr/bin/ruby
    > exec "apt-get install gaim";
    >
    > this script run that command on shell
    >
    >


    for posterity, this does run through the shell, rather it replaces
    ruby with the argument to exec (another process) completely by-passes
    the shell. you need to use system or popen to utilize the shell.

    regards.

    -a
    --
    we can deny everything, except that we have the possibility of being
    better. simply reflect on that.
    h.h. the 14th dalai lama
    ara.t.howard, May 20, 2007
    #10
    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:
    5,701
    Jonathan Bromley
    Feb 18, 2005
  2. Haihui Guo
    Replies:
    1
    Views:
    26,646
    Haihui Guo
    Jun 12, 2005
  3. Replies:
    4
    Views:
    1,708
    Terry Hancock
    Apr 23, 2005
  4. Donald Duck

    Best command for running shell command

    Donald Duck, Jul 11, 2006, in forum: Python
    Replies:
    3
    Views:
    405
    iapain
    Jul 11, 2006
  5. Sonu
    Replies:
    2
    Views:
    371
    Alex Popescu
    Aug 5, 2007
Loading...

Share This Page