27
votes

I wanna open pdf file from python console, I can do it with os.system(filename), it will open in adobe reader, but the problem is that os.system also opens a command prompt, is there another way that won't open command prompt?

5

5 Answers

26
votes

Try:

import subprocess
subprocess.Popen([file],shell=True)
16
votes
import webbrowser
webbrowser.open_new(r'file://C:\path\to\file.pdf')
14
votes
import os
os.startfile(filename)
0
votes

This is a bit late but nobody mentioned:

open("file_name.pdf")
0
votes

Read the documentation thoroughly. The very first line of the os.system method is:

Execute the command (a string) in a subshell.

Knowing this, you can now seek alternate solutions, such as the subprocess module already mentioned.