0

I have a piece of python that needs to open up a file in OSX, via its default application, that is selected inside Tkinter file open control. I do not know what the file type is when it is selected nor the default app.

Tk().withdraw()
filename = askopenfilename()

child = subprocess.check_call("open" ,filename)

My problem is this does not work...if I include shell=True is does but I need to capture the PID of the application that started not the pid of the shell that executed the command.

Any thoughts?

Thanks C

4

1 回答 1

1

If the shell keyword argument is False the input must be a sequence. Also you're passing the filename as the second argument, instead of into the first.

child = subprocess.check_call(["open", filename])

to quote the docs:

The shell argument (which defaults to False) specifies whether to use the shell as the program to execute. If shell is True, it is recommended to pass args as a string rather than as a sequence.

于 2013-07-31T22:03:34.500 回答