Opening a file with system default application

T

tactics40

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

BartlebyScrivener

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

import os

os.system('mytextfile.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
 
T

tac-tics

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

import os

os.system('mytextfile.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

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

BartlebyScrivener

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
 
M

Marc 'BlackJack' Rintsch

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

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

Ciao,
Marc 'BlackJack' Rintsch
 
D

Dennis Lee Bieber

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

import os

os.system('mytextfile.txt')

Whatever file you reference should open in the application associated
with it. At least that's the way it works on Win XP
That also pops up a command shell window, which may not be
desirable. On Windows, there is

os.startfile("someknown.type")

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
B

BartlebyScrivener

That also pops up a command shell window, which may not be
Ack. You're right. I get them mixed up. And os.startfile is Windows
only.

Sorry.

rd
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top