Invoking a windows application (e.g notepad) from ruby

Discussion in 'Ruby' started by Anukul Singhal, Mar 19, 2008.

  1. Hi,

    I wanted to know if there is any utility present in ruby through which
    we can invoke an external windows app (notepad.exe) or any exe.

    Can anyone please help me with the relevant code in ruby which can do
    so?

    Thanks,
    Anukul
    --
    Posted via http://www.ruby-forum.com/.
     
    Anukul Singhal, Mar 19, 2008
    #1
    1. Advertising

  2. Anukul Singhal wrote:
    > Hi,
    >
    > I wanted to know if there is any utility present in ruby through which
    > we can invoke an external windows app (notepad.exe) or any exe.
    >
    > Can anyone please help me with the relevant code in ruby which can do
    > so?
    >
    > Thanks,
    > Anukul


    The short way:


    `notepad`

    Note these are backticks, not single quotes. Ruby will wait until
    notepad is finished. If the waiting is not desired, this is an option:

    system("start notepad")
    system("calc")

    Possibly you have to provide the full path to the executable.

    Regards,

    Siep


    --
    Posted via http://www.ruby-forum.com/.
     
    Siep Korteling, Mar 19, 2008
    #2
    1. Advertising

  3. Anukul Singhal

    Jano Svitok Guest

    On Wed, Mar 19, 2008 at 11:42 PM, Anukul Singhal
    <> wrote:
    > Hi,
    >
    > I wanted to know if there is any utility present in ruby through which
    > we can invoke an external windows app (notepad.exe) or any exe.
    >
    > Can anyone please help me with the relevant code in ruby which can do
    > so?


    if you want to wait until the program finishes:
    system "notepad"
    if you don't want:
    system "start notepad"

    see also Kernel#`

    note that if you need to quote the program name, you have to add
    another pair of quotes, because start
    threats the first quoted string as window title.

    system 'start "" "C:\Program Files\whaterver.exe"'
     
    Jano Svitok, Mar 19, 2008
    #3
  4. Siep Korteling wrote:
    > Anukul Singhal wrote:
    >> Hi,
    >>
    >> I wanted to know if there is any utility present in ruby through which
    >> we can invoke an external windows app (notepad.exe) or any exe.
    >>
    >> Can anyone please help me with the relevant code in ruby which can do
    >> so?
    >>
    >> Thanks,
    >> Anukul

    >
    > The short way:
    >
    >
    > `notepad`
    >
    > Note these are backticks, not single quotes. Ruby will wait until
    > notepad is finished. If the waiting is not desired, this is an option:
    >
    > system("start notepad")
    > system("calc")
    >
    > Possibly you have to provide the full path to the executable.
    >
    > Regards,
    >
    > Siep


    ----------------------------------------

    Siep, Thanks a lot!!

    ..Anukul
    --
    Posted via http://www.ruby-forum.com/.
     
    Anukul Singhal, Mar 20, 2008
    #4
  5. Jano Svitok wrote:
    > On Wed, Mar 19, 2008 at 11:42 PM, Anukul Singhal
    > <> wrote:
    >> Hi,
    >>
    >> I wanted to know if there is any utility present in ruby through which
    >> we can invoke an external windows app (notepad.exe) or any exe.
    >>
    >> Can anyone please help me with the relevant code in ruby which can do
    >> so?

    >
    > if you want to wait until the program finishes:
    > system "notepad"
    > if you don't want:
    > system "start notepad"
    >
    > see also Kernel#`
    >
    > note that if you need to quote the program name, you have to add
    > another pair of quotes, because start
    > threats the first quoted string as window title.
    >
    > system 'start "" "C:\Program Files\whaterver.exe"'


    ---------------------------------------

    Jano, thanks a lot!

    ..Anukul

    --
    Posted via http://www.ruby-forum.com/.
     
    Anukul Singhal, Mar 20, 2008
    #5
    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. Roger
    Replies:
    1
    Views:
    300
    Larry Bates
    Mar 2, 2004
  2. Chetan Gadgil
    Replies:
    1
    Views:
    330
    Roger
    Mar 4, 2004
  3. Anukul Singhal
    Replies:
    3
    Views:
    163
  4. max
    Replies:
    3
    Views:
    434
  5. UnRiel
    Replies:
    24
    Views:
    315
    Dr.Ruud
    Jul 9, 2008
Loading...

Share This Page