Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to open a file in windows

Reply
Thread Tools

How to open a file in windows

 
 
Nicolas Galler
Guest
Posts: n/a
 
      08-19-2003
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


 
Reply With Quote
 
 
 
 
Hal E. Fulton
Guest
Posts: n/a
 
      08-19-2003
----- Original Message -----
From: "Nicolas Galler" <>
To: "ruby-talk ML" <ruby->
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

--
Hal Fulton



 
Reply With Quote
 
 
 
 
Dan Doel
Guest
Posts: n/a
 
      08-19-2003
`start <filename>`

Also works on Windows XP (just checked).

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

- Dan


 
Reply With Quote
 
Niklas Frykholm
Guest
Posts: n/a
 
      08-19-2003
Dan Doel wrote:

> `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

 
Reply With Quote
 
Bernard Delmée
Guest
Posts: n/a
 
      08-19-2003
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
);



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
File::open and File.open Brad Tilley Ruby 4 10-24-2006 09:34 PM
C# code needed to open the windows "Open with" dialog Shilpa ASP .Net 1 03-22-2006 12:17 PM
How Can I Open or Extract CAB files That Doesn't Open w/WinZip, WinRAR nor the Windows CAB viewer? NoLikey Spam Computer Support 5 12-17-2003 11:12 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57