Opening a file with system default application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tactics40@gmail.com

    #1

    Opening a file with system default application

    I'm writing a GUI application in Jython which takes a database text
    file and performs some operations on the data, finally spitting out a
    group of CSV files.

    I generate a log file and several CSV files and I thought it would be
    helpful if I could add a button the user could click on to
    automatically launch the log file or the CSV output files using the
    default text editor / spreadsheet editor on their system.

    Does Python (or Java, since I'm using jython) have a clean cut way to
    do this?

  • BartlebyScrivener

    #2
    Re: Opening a file with system default application

    don't know Jython, but in Python, I think you want:

    import os

    os.system('myte xtfile.txt')

    Whatever file you reference should open in the application associated
    with it. At least that's the way it works on Win XP

    rd

    Comment

    • tac-tics

      #3
      Re: Opening a file with system default application

      BartlebyScriven er wrote:[color=blue]
      > don't know Jython, but in Python, I think you want:
      >
      > import os
      >
      > os.system('myte xtfile.txt')
      >
      > Whatever file you reference should open in the application associated
      > with it. At least that's the way it works on Win XP
      >
      > rd[/color]

      I didn't think about that. It would probably break like mad under *nix
      that fine. This will solve my issue.

      Thanks =-)

      Even still, does anyone know if there is a more platform indepedent way
      to do this?

      Comment

      • BartlebyScrivener

        #4
        Re: Opening a file with system default application

        >> It would probably break like mad under *nix

        I bet it would work the same way on linux or os x; it's the equivalent
        of double-clicking on the file.

        rd

        Comment

        • Marc 'BlackJack' Rintsch

          #5
          Re: Opening a file with system default application

          In <1151081172.418 493.190730@i40g 2000cwc.googleg roups.com>,
          BartlebyScriven er wrote:
          [color=blue][color=green][color=darkred]
          >>> It would probably break like mad under *nix[/color][/color]
          >
          > I bet it would work the same way on linux or os x; it's the equivalent
          > of double-clicking on the file.[/color]

          No it doesn't work. Double clicking is not an OS thing but a a GUI thing.

          Ciao,
          Marc 'BlackJack' Rintsch

          Comment

          • Cameron Laird

            #6
            Re: Opening a file with system default application

            In article <pan.2006.06.23 .17.31.46.25174 0@gmx.net>,
            Marc 'BlackJack' Rintsch <bj_666@gmx.net > wrote:[color=blue]
            >In <1151081172.418 493.190730@i40g 2000cwc.googleg roups.com>,
            >BartlebyScrive ner wrote:
            >[color=green][color=darkred]
            >>>> It would probably break like mad under *nix[/color]
            >>
            >> I bet it would work the same way on linux or os x; it's the equivalent
            >> of double-clicking on the file.[/color]
            >
            >No it doesn't work. Double clicking is not an OS thing but a a GUI thing.[/color]

            Comment

            • BartlebyScrivener

              #7
              Re: Opening a file with system default application

              >>> That also pops up a command shell window, which may not be[color=blue][color=green][color=darkred]
              >>> desirable. On Windows, there is[/color][/color][/color]
              [color=blue][color=green][color=darkred]
              >>> os.startfile("s omeknown.type")[/color][/color][/color]

              Ack. You're right. I get them mixed up. And os.startfile is Windows
              only.

              Sorry.

              rd

              Comment

              Working...