# Opening my files with a ruby program

**URL:** <https://www.ruby-forum.com/t/opening-my-files-with-a-ruby-program/188750>\
**Category:** Ruby\
**Created:** [May 17, 2010, 7:38pm UTC](https://www.ruby-forum.com/t/opening-my-files-with-a-ruby-program/188750 "2010-05-17T19:38:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 17, 2010, 7:38pm UTC](https://www.ruby-forum.com/t/opening-my-files-with-a-ruby-program/188750/1 "2010-05-17T19:38:43Z")

</div>

i was just wondering if i wanted my program to open a file on my pc what  
would i put for example if i wanted to use ruby irb to open media player  
thanks

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 17, 2010, 8:13pm UTC](https://www.ruby-forum.com/t/opening-my-files-with-a-ruby-program/188750/2 "2010-05-17T20:13:19Z")

</div>

Mark K. wrote:

> i was just wondering if i wanted my program to open a file on my pc what  
> would i put for example if i wanted to use ruby irb to open media player  
> thanks

You’ve to find out what the Media Player’s executable is named and if it  
accepts the filename as a command-line argument. That said, I’m assuming  
the executable is called “mplayer” and your file “myfile.ogg”.

system(“mplayer”, “myfile.ogg”)

That blocks until the mplayer process exits, so you may want this  
instead:

#On \*nix  
spawn(“mplayer”, “myfile.ogg”)  
#On Windows or \*nix  
IO.popen(“mplayer myfile.ogg”)

How to find out the executables name:  
Right-click on your favourite starting icon, choose something like  
“Settings”, look what command it runs or what goal it points to and use  
that instead of “mplayer” in my example.

And you may think about using punctuation?

Marvin

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 17, 2010, 9:19pm UTC](https://www.ruby-forum.com/t/opening-my-files-with-a-ruby-program/188750/3 "2010-05-17T21:19:26Z")

</div>

Besides the ones Marvin mentioned, you also have a couple of other  
options.

the example below will open the JPG image using the default program used  
to  
handle JPG files  
system(‘cmd /c start “”  
C:\DOCUME~1\churchil\MYDOCU~1\MYDROP~1\images\SABBAT~1.JPG’)

while this example will open it explicitly with mspaint  
system(‘cmd /c start “” C:\WINDOWS\system32\mspaint.exe  
C:\DOCUME~1\churchil\MYDOCU~1\MYDROP~1\images\SABBAT~1.JPG’)

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 17, 2010, 9:28pm UTC](https://www.ruby-forum.com/t/opening-my-files-with-a-ruby-program/188750/4 "2010-05-17T21:28:48Z")

</div>

And actually, I don’t think you need the “cmd /c”

You can just use system(‘start “”  
C:\DOCUME~1\churchil\MYDOCU~1\MYDROP~1\images\SABBAT~1.JPG’)
