473,416 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

os.startfile and unknown file extension

75
I need to open PDF file with my python application, and I'm using os.startfile(filename.pdf) command, I would need open command act 100% like clicking the file in the windows explorer

python documentation about os.startfile: "Start a file with its associated application. This acts like double-clicking the file in Windows Explorer, or giving the file name as an argument to the start command from the interactive command shell: the file is opened with whatever application (if any) its extension is associated."

well this isn't true! what happens when you doubleclick file with unknown file extension in Windows Explorer? popup appears saying that the file extension is unknown! and this isn't happening when using os.startfile()

does anyone have solution for this?

os.startfile() returns error "1155", No application is associated with the specified file for this operation

so should I check for this error message and then manually start that unknown file extension popup "application" ? not really a python question but does anyone know how to start that popup externally? =)
Apr 2 '08 #1
2 8020
dazzler
75
ok, I have almost solved the problem

Expand|Select|Wrap|Line Numbers
  1. try:
  2.    os.startfile("testfile.pdf")
  3. except Expection, errorcode:
  4.  
  5.    if errorcode[0] = 1155:
  6.       os.popen("Rundll32.exe SHELL32.dll, OpenAs_RunDLL testfile.pdf")
  7.    else:
  8.       print "other error"
  9.  
this works but as you know os.popen stops python code and not resume until I close it, I need to my code continue ofcourse and not stop for that popup =(

how to use os.startfile() with "Rundll32.exe SHELL32.dll, OpenAs_RunDLL testfile.pdf" command =/ it seems that os.startfile() take only filename and not any optional arguments

you can yourself try in windows using start->run... and see how the "Rundll32.exe SHELL32.dll, OpenAs_RunDLL testfile.pdf" acts :)
Apr 2 '08 #2
dazzler
75
instead of
Expand|Select|Wrap|Line Numbers
  1. os.popen("Rundll32.exe SHELL32.dll, OpenAs_RunDLL testfile.pdf")
  2.  
I tried
Expand|Select|Wrap|Line Numbers
  1. os.spawnl(os.P_NOWAIT, os.environ['WINDIR']+"/system32/Rundll32.exe", "Rundll32.exe SHELL32.DLL, OpenAs_RunDLL testfile.pdf")
  2.  
os.environ['WINDIR'] points to c:/windows or whatever the win installation directory is

it isn't pretty but it works, don't know why I have to give the name "Rundll32.exe" in the argument also, well it doesn't matter what there is ("a" works also) but if I dont give it, it won't work. maybe it's some linux thing =p

if someone knows cleaner solution, tell me =)
Apr 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Stefan | last post by:
Hi, I just downloaded PHP-4.3.3 for win32 and got the extensions folder and dropped it intot he root of the PHP directory and set it's path in the PHP.ini: extension_dir =...
2
by: Christian Seberino | last post by:
I have a program that has Python and C code. I added Extension stuff to setup.py and all .c and .h files get into tarball fine. (I have something like Extension("foo", glob.glob("bar/*.") ) ...
2
by: Matthias Huening | last post by:
Hi, os.startfile('http://www.python.org') works fine on WinXP with IE as default webbrowser. With Mozilla Firefox 0.9 as default webbrowser, however, I get an error. Firefox starts, the page...
6
by: Timothy Smith | last post by:
hello i have a very odd issue with os.startfile() ok basicly my app works perfectly on every single other pc todate. i cannot recreate this issue on any system. so i've already ruled out any...
3
by: BartlebyScrivener | last post by:
Can any Windows user give a working example of adding a "command verb" to os.startfile()? When I try it, it squawks that it takes only one argument. >>> os.startfile('d:/','explore')...
7
by: (PeteCresswell) | last post by:
I've got a UNC. It's something like H:\CDL\Attachments\Deal000023.InitialOffering.doc. I want to feed that UNC to MS Windows and let Windows worry about selecting which application to use to...
6
by: delusion7 | last post by:
I keep getting this error and/or similar errors. I am very new to mysql and php. "PHP Warning: Unknown(): Unable to load dynamic library './php_mysqli.dll' - The specified module could not be...
7
by: Abhi | last post by:
Hi, I want to open a File with unknown Extension using C#. What i want is i do System.Diagnostics.Process.Start("FileName"); Now if File is associated with any program then the File with open...
1
by: Alexnb | last post by:
So i have a mac and pc, and just found out that os.startfile() doesn't work on a mac. So is there anything like that besides os.system()? -- View this message in context:...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.