# Ruby Equivalent to Python os.startfile?

**URL:** <https://www.ruby-forum.com/t/ruby-equivalent-to-python-os-startfile/108718>\
**Category:** Ruby\
**Created:** [July 6, 2007, 9:05am UTC](https://www.ruby-forum.com/t/ruby-equivalent-to-python-os-startfile/108718 "2007-07-06T09:05:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrishel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/df705f/32.png) [@wrishel](https://www.ruby-forum.com/u/wrishel)\
**Post date:** [July 6, 2007, 9:05am UTC](https://www.ruby-forum.com/t/ruby-equivalent-to-python-os-startfile/108718/1 "2007-07-06T09:05:20Z")

</div>

In Windows cmd.exe, if I enter the name of a file with a Windows  
extension, Windows will start the file as if I double clicked on it in  
Windows explorer. E.g.

D:/Documents and Settings/WRishel/My Documents/DailyNotes\>070701.doc  
[Word starts and opens the file 070701.doc]

In Python I can achieve the same result by using

os.startfile(“D:/Documents and Settings/WRishel/My  
Documents/DailyNotes/070701.doc”)

However I have not been able to find the equivalent method in Ruby.

Exec gives Errno::ENOEXEC: Exec format error

Any suggestions?

---

<div class="post-metadata">

**Author:** ![wrishel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/df705f/32.png) [@wrishel](https://www.ruby-forum.com/u/wrishel)\
**Post date:** [July 6, 2007, 9:17am UTC](https://www.ruby-forum.com/t/ruby-equivalent-to-python-os-startfile/108718/2 "2007-07-06T09:17:30Z")

</div>

From: “Wesley R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> In Windows cmd.exe, if I enter the name of a file with a Windows  
> extension, Windows will start the file as if I double clicked on it in  
> Windows explorer. E.g.
> 
> D:/Documents and Settings/WRishel/My Documents/DailyNotes\>070701.doc  
> [Word starts and opens the file 070701.doc]

Seems to work on XP:

system(“start D:/Documents and Settings/WRishel/My  
Documents/DailyNotes/070701.doc”)

Hope this helps,

Bill

---

<div class="post-metadata">

**Author:** ![wrishel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/df705f/32.png) [@wrishel](https://www.ruby-forum.com/u/wrishel)\
**Post date:** [July 6, 2007, 6:30pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-to-python-os-startfile/108718/3 "2007-07-06T18:30:30Z")

</div>

Bill – thanks very helpful. At least on my XP system it takes two more  
tweaks to make it work, or a tweak and a counter-tweak.

Tweak: For some reason, on my system, system() and exec() don’t handle  
the path with embedded spaces properly. I have to wrap the path in  
double-quote marks.

Counter-tweak: The Windows command language, well known as a bastion of  
inconsistency :-), treats the first parameter of a Start command  
differently when it is enclosed in quotes. It becomes the title for the  
Window.

This adaptation of your suggestion seems to work for me.

system(‘start “” “D:/Documents and Settings/WRishel/My  
Documents/DailyNotes/070701.doc”’)

Bill K. wrote:

> From: “Wesley R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > In Windows cmd.exe, if I enter the name of a file with a Windows  
> > extension, Windows will start the file as if I double clicked on it in  
> > Windows explorer. E.g.
> > 
> > D:/Documents and Settings/WRishel/My Documents/DailyNotes\>070701.doc  
> > [Word starts and opens the file 070701.doc]
> 
> Seems to work on XP:
> 
> system(“start D:/Documents and Settings/WRishel/My  
> Documents/DailyNotes/070701.doc”)
> 
> Hope this helps,
> 
> Bill

---

<div class="post-metadata">

**Author:** ![wrishel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/df705f/32.png) [@wrishel](https://www.ruby-forum.com/u/wrishel)\
**Post date:** [July 6, 2007, 8:34pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-to-python-os-startfile/108718/4 "2007-07-06T20:34:26Z")

</div>

Does

system(‘start D:/Documents and Settings/WRishel/My  
Documents/DailyNotes/070701.doc’)

work?

I think I’ve seen this use, though rethinking it doesn’t make much sense  
now :S

Aur

---

<div class="post-metadata">

**Author:** ![wrishel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/df705f/32.png) [@wrishel](https://www.ruby-forum.com/u/wrishel)\
**Post date:** [July 6, 2007, 8:59pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-to-python-os-startfile/108718/5 "2007-07-06T20:59:28Z")

</div>

Thanks. I found that this approach needs a couple of tweaks:

Tweak: For some reason, on my system, system() and exec() don’t handle  
the path with embedded spaces properly. I have to wrap the path in  
double-quote marks.

Counter-tweak: The Windows command language, well known as a bastion of  
consistency :-), treats the first parameter of a Start command  
differently when it is enclosed in quotes. It becomes the title for the  
Window.

This adaptation of your suggestion seems to work for me.

system(‘start “” “D:/Documents and Settings/WRishel/My  
Documents/DailyNotes/070701.doc”’)
