Professional Web Applications Themes

How to open a file in windows - Ruby

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

  1. #1

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

    Thanks
    Nick


    Nicolas Galler Guest

  2. #2

    Default Re: How to open a file in windows

    ----- Original Message -----
    From: "Nicolas Galler" <beaniegryphonmud.com>
    To: "ruby-talk ML" <ruby-talkruby-lang.org>
    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
    [email]hal9000hypermetrics.com[/email]


    Hal E. Fulton Guest

  3. #3

    Default Re: How to open a file in windows

    `start <filename>`

    Also works on Windows XP (just checked).

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

    - Dan


    Dan Doel Guest

  4. #4

    Default Re: How to open a file in windows

    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 doents and GUI programs, run() is for console
    programs (so that I can get their output in the console).

    // Niklas

    Niklas Frykholm Guest

  5. #5

    Default Re: How to open a file in windows

    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
    );



    Bernard Delmée Guest

Similar Threads

  1. Duplicate files open anytime I open a file
    By Steve_O_Connell@adobeforums.com in forum Adobe Illustrator Windows
    Replies: 4
    Last Post: August 6th, 06:11 PM
  2. unable to open mac eps file contains illegal operand in windows
    By Michael_Appelmans@adobeforums.com in forum Adobe Illustrator Windows
    Replies: 1
    Last Post: July 3rd, 03:45 PM
  3. Open file, make changes, save file, close, re-open, file contents not changed
    By brock@bergdesign.com in forum Adobe Illustrator Macintosh
    Replies: 7
    Last Post: March 7th, 07:29 PM
  4. Open a flash file from another file in seperate windows.
    By Shawn Centers in forum Macromedia Flash
    Replies: 0
    Last Post: October 31st, 02:30 AM
  5. Help - need a file - can't open windows?!
    By Pete Stockdale in forum Windows XP/2000/ME
    Replies: 8
    Last Post: July 21st, 01:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139