How to open a file in windows

N

Nicolas Galler

Hello,

I am trying to offer a way to play audio files from my ruby program (by
running the appropriate application, not actually embedding a player :)

It's not really a problem under unix but under windows I would like the app to
automatically use the 'default' player for the type of files - is there a
straightforward way to do that?

Thanks
Nick
 
H

Hal E. Fulton

----- Original Message -----
From: "Nicolas Galler" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Tuesday, August 19, 2003 12:02 AM
Subject: How to open a file in windows

Hello,

I am trying to offer a way to play audio files from my ruby program (by
running the appropriate application, not actually embedding a player :)

It's not really a problem under unix but under windows I would like the app to
automatically use the 'default' player for the type of files - is there a
straightforward way to do that?

On Win98 there's a "start" executable that will crank up
the app associated with the file given as a parameter.

Don't know if it exists in more modern Windowses. But
those do have assoc and ftype or some such... with the
help of those, you might just "execute" the .wav or
whatever as though it were a .exe -- but I'm only
guessing.

Hal
 
D

Dan Doel

`start <filename>`

Also works on Windows XP (just checked).

`<filename>` doesn't (although I thought it would).

- Dan
 
N

Niklas Frykholm

Dan said:
`start <filename>`

Also works on Windows XP (just checked).

`<filename>` doesn't (although I thought it would).

I use:

module Win32

def Win32.start(file, *args)
cmd = "\"#{file}\" " + \
(args.collect {|x| "\"#{x}\""}.join ' ')
puts cmd
system('start "" ' + cmd)
end

def Win32.run(file, *args)
cmd = "\"#{file}\" " + \
(args.collect {|x| "\"#{x}\""}.join ' ')
puts cmd
system(cmd)
end

end

start() is for opening documents and GUI programs, run() is for console
programs (so that I can get their output in the console).

// Niklas
 
B

Bernard Delmée

Suggestions to use "start" are correct but I think they'll
always launch a DOS console. Besides, the command interpreter
will have to be "command" on win9x/ME but "cmd" on NT/2000/XP.
What you will want is an extension which exposes the ShellExecute
win32 API, if there is such a beast... Otherwise, it should be
possible to wrap it using the Win32API class, given that the
proc signature is the following:

HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top