[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Anukul Singhal

3/19/2008 10:42:00 PM

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-....

4 Answers

Siep Korteling

3/19/2008 11:07:00 PM

0

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-....

Jano Svitok

3/19/2008 11:09:00 PM

0

On Wed, Mar 19, 2008 at 11:42 PM, Anukul Singhal
<anukul.singhal@gmail.com> 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"'

Anukul Singhal

3/20/2008 7:01:00 AM

0

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-....

Anukul Singhal

3/20/2008 7:02:00 AM

0

Jano Svitok wrote:
> On Wed, Mar 19, 2008 at 11:42 PM, Anukul Singhal
> <anukul.singhal@gmail.com> 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-....