# How to invoke Windows program with a Ruby command

**URL:** <https://www.ruby-forum.com/t/how-to-invoke-windows-program-with-a-ruby-command/151813>\
**Category:** Ruby\
**Created:** [October 26, 2008, 5:25am UTC](https://www.ruby-forum.com/t/how-to-invoke-windows-program-with-a-ruby-command/151813 "2008-10-26T05:25:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [October 26, 2008, 5:25am UTC](https://www.ruby-forum.com/t/how-to-invoke-windows-program-with-a-ruby-command/151813/1 "2008-10-26T05:25:32Z")

</div>

Hi,

I’ve got a command that works in the Command Window of WinXP-Pro/SP3:

F:\Docume~1\AllUse~1\StartM~1\Programs\_Microsoft  
\Micros~3\Micros~2.lnk  
K:\_Projects\Ruby\_Rails\_Apps\PayrollLoader\TestSheet.xls

As I write this post, the command is written on two lines. But in  
the Command Windows are submitted as a single line with a space  
separating the program from the argument. The command brings up Excel  
with the content from the file named in the program’s argument.

However, I have not been able to get this to work in Ruby with  
system(pgm\_name, file\_name). The command does nothing. It doesn’t  
crash, as evidenced by the fact that following commands are executed  
correctly.

How can I achieve the Command Window result with Ruby 1.8.6?

Thanks in Advance,  
Richard

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [October 26, 2008, 11:14am UTC](https://www.ruby-forum.com/t/how-to-invoke-windows-program-with-a-ruby-command/151813/2 "2008-10-26T11:14:34Z")

</div>

RichardOnRails wrote:

> separating the program from the argument. The command brings up Excel  
> with the content from the file named in the program’s argument.
> 
> However, I have not been able to get this to work in Ruby with  
> system(pgm\_name, file\_name). The command does nothing. It doesn’t  
> crash, as evidenced by the fact that following commands are executed  
> correctly.
> 
> How can I achieve the Command Window result with Ruby 1.8.6?

Took me a while to get this working.

Here’s what works:  
#make sure that the name of the executable is within quotes  
exec\_link = ““c:\Documents and Settings\Mohit\Start Menu\Quick  
Start\TextPad.lnk””  
#make sure that the document name is within quotes  
doc\_name = ““e:\projects\tedn01\extract\01.extract\_styles.rb””

#launch the ‘link’ using cmd  
my\_exec = "cmd /C “#{exec\_link} #{doc\_name}” "

puts my\_exec  
ret = system(my\_exec)  
puts ret

Hope this helps.

Cheers,  
Mohit.  
10/26/2008 | 6:13 PM.

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [October 27, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/how-to-invoke-windows-program-with-a-ruby-command/151813/3 "2008-10-27T23:36:00Z")

</div>

On Oct 26, 5:23 am, RichardOnRails  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> separating the program from the argument. The command brings up Excel  
> Richard  
> There are many ways to redirect output from your system call.  
> Take look at: [Batch files - Redirection](http://www.robvanderwoude.com/redirection.html)

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [October 28, 2008, 9:25am UTC](https://www.ruby-forum.com/t/how-to-invoke-windows-program-with-a-ruby-command/151813/4 "2008-10-28T09:25:11Z")

</div>

> As I write this post, the command is written on two lines. But in  
> the Command Windows are submitted as a single line with a space  
> separating the program from the argument. The command brings up Excel  
> with the content from the file named in the program’s argument.

Might be able to use system(“start filename\_here”)  
Good luck.
