473,545 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

os.startfile and unknown file extension

75 New Member
I need to open PDF file with my python application, and I'm using os.startfile(fi lename.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 "applicatio n" ? not really a python question but does anyone know how to start that popup externally? =)
Apr 2 '08 #1
2 8045
dazzler
75 New Member
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.e xe 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.e xe SHELL32.dll, OpenAs_RunDLL testfile.pdf" acts :)
Apr 2 '08 #2
dazzler
75 New Member
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.e xe" 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
20604
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 = "c:/php/extensions/" But I am still getting the error that it can't find the php_mhash.dll though I can see that it is indeed in the folder.
2
2300
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/*.") ) When I try to INSTALL the package it says header (.h) file is an unknown type. How fix this???
2
3477
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 gets loaded and then Python gives me an error message (Traceback below). The same is true for the webbowser module. Is this a Python problem or a...
6
2121
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 obvious coding issues, such as wrong file names etc. this issue only occurs on this one old pc. upon trying to os.startfile() a pdf document (that i...
3
16590
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') Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: startfile() takes exactly 1 argument (2 given)
7
7498
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 open it. If there's no app defined for that UNC's particular suffix, that's ok... we'll live with it. Seems like a FileSystemObject should be...
6
3835
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 found. in Unknown on line 0 " and "PHP Warning: Unknown(): Unable to load dynamic library 'C:\PHP\php_mysqli.dll' - The specified module could not be...
7
11651
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 with that Application, this is working fine. My requirement says, if file extension is unknown or not associated with any application then, it should...
1
3490
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: http://www.nabble.com/os.startfile%28%29-on-a-mac-tp17829335p17829335.html Sent from the Python - python-list mailing list archive at Nabble.com.
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7751
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4943
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.