Forum: Ruby Ruby Equivalent to Python os.startfile ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eda71a7571c2c99c4765f5fa2841664a?d=identicon&s=25 Wesley Rishel (wrishel)
on 2007-07-06 09:05
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?
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2007-07-06 09:17
(Received via mailing list)
From: "Wesley Rishel" <wes.rishel@gartner.com>
>
> 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
Eda71a7571c2c99c4765f5fa2841664a?d=identicon&s=25 Wesley Rishel (wrishel)
on 2007-07-06 18:30
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 Kelly wrote:
> From: "Wesley Rishel" <wes.rishel@gartner.com>
>>
>> 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
7b4707f974af261f71943e1f2046c9ee?d=identicon&s=25 SonOfLilit (Guest)
on 2007-07-06 20:34
(Received via mailing list)
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
Eda71a7571c2c99c4765f5fa2841664a?d=identicon&s=25 Wesley Rishel (wrishel)
on 2007-07-06 20:59
(Received via mailing list)
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"')
This topic is locked and can not be replied to.