How to open a file in windows

Discussion in 'Ruby' started by Nicolas Galler, Aug 19, 2003.

  1. 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, Aug 19, 2003
    #1
    1. Advertising

  2. ----- Original Message -----
    From: "Nicolas Galler" <>
    To: "ruby-talk ML" <>
    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
     
    Hal E. Fulton, Aug 19, 2003
    #2
    1. Advertising

  3. Nicolas Galler

    Dan Doel Guest

    `start <filename>`

    Also works on Windows XP (just checked).

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

    - Dan
     
    Dan Doel, Aug 19, 2003
    #3
  4. 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
     
    Niklas Frykholm, Aug 19, 2003
    #4
  5. 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, Aug 19, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shilpa
    Replies:
    1
    Views:
    6,077
    Anubhav Jain
    Mar 22, 2006
  2. THY
    Replies:
    4
    Views:
    532
    Gönen EREN
    Aug 22, 2003
  3. RJN
    Replies:
    2
    Views:
    4,981
  4. Schüle Daniel

    File::open and File.open

    Schüle Daniel, Oct 23, 2006, in forum: Ruby
    Replies:
    4
    Views:
    212
    Rick DeNatale
    Oct 24, 2006
  5. Replies:
    1
    Views:
    262
Loading...

Share This Page