Ruby Equivalent to Python os.startfile ?

W

Wesley Rishel

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?
 
B

Bill Kelly

From: "Wesley Rishel said:
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
 
W

Wesley Rishel

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 said:
From: "Wesley Rishel said:
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
 
S

SonOfLilit

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

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 said:
From: "Wesley Rishel said:
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
 
R

Rishel,Wes

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"')


-----Original Message-----
From: SonOfLilit [mailto:[email protected]]=20
Sent: Friday, July 06, 2007 11:33 AM
To: ruby-talk ML
Subject: Re: Ruby Equivalent to Python os.startfile ?

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

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 said:
From: "Wesley Rishel said:
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

This e-mail message, including any attachments, is for the sole use of =
the person to whom it has been sent, and may contain information that is =
confidential or legally protected. If you are not the intended recipient =
or have received this message in error, you are not authorized to copy, =
distribute, or otherwise use this message or its attachments. Please =
notify the sender immediately by return e-mail and permanently delete =
this message and any attachments. Gartner makes no warranty that this =
e-mail is error or virus free.=20
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,082
Latest member
KetonaraKetoACV

Latest Threads

Top