Handling CD Drives from python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Handling CD Drives from python

 
0
  #1
Mar 20th, 2007
Hey,

Just a simple question really, i was looking through the documentation for python and i couldn't find anything that did basic cd drive things, like ejecting it and stuff. The one module i did find 'cd' was only compatible on IRIX systems.

After failing miserably on google i was just wondering if anyone happened to know of a command or module that opens the cd drive, and reads from it, seems simple but meh..

I'm hoping theres something built in that does it.

Thanks,
a1eio
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 9
Reputation: coder_gus is an unknown quantity at this point 
Solved Threads: 0
coder_gus's Avatar
coder_gus coder_gus is offline Offline
Newbie Poster

Re: Handling CD Drives from python

 
0
  #2
Mar 20th, 2007
You could use os.popen if you are on unix like operating systems to run shell commands like nautilus-cd-burner or anything you like.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Re: Handling CD Drives from python

 
0
  #3
Mar 21st, 2007
yea, i forgot to mention, i'm trying to do this on a windows machine.

the os.popen idea did occur to me, but then i got stuck again.. :p i don't know the dos command for opening the cd drive.

thanks
a1eio
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: Handling CD Drives from python

 
0
  #4
Mar 21st, 2007
Originally Posted by a1eio View Post
yea, i forgot to mention, i'm trying to do this on a windows machine.

the os.popen idea did occur to me, but then i got stuck again.. :p i don't know the dos command for opening the cd drive.

thanks
a1eio
if you have pygame, you can use its inbuilt cdrom commands
  1. import pygame.cdrom as cdrom
  2. cdrom.init()
  3. cd = cdrom.CD(0) # 0 = first cdrom device
  4. cd.init()
  5. cd.eject()
  6. cd.quit()
  7. cdrom.quit()

or here's something i found GNU CD Input and Control Library . you can try it out.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 21
Reputation: myle is an unknown quantity at this point 
Solved Threads: 2
myle myle is offline Offline
Newbie Poster

Re: Handling CD Drives from python

 
0
  #5
Sep 3rd, 2009
Is there any way (non platform-depended) to close the tray using python 3.

I couldn't find any function in the api of pygame.cdrom module. The best result so far is for Windows.

http://code.activestate.com/recipes/180919/
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,384
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is online now Online
Nearly a Posting Virtuoso

Re: Handling CD Drives from python

 
0
  #6
Sep 4th, 2009
on windows use os.system("YOUR EJECT COMMAND HERE")
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,028
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Handling CD Drives from python

 
0
  #7
Sep 4th, 2009
Here is one that works on Windows machines with Python3 ...
  1. # open and close the CD tray door (Windows OS)
  2. # tested with Python 3.1
  3.  
  4. import ctypes
  5. import time
  6.  
  7. # open the CD tray door
  8. ctypes.windll.winmm.mciSendStringW("set cdaudio door open",
  9. None, 0, None)
  10.  
  11. # wait 3.5 seconds
  12. time.sleep(3.5)
  13.  
  14. # close the CD tray (manual closing only with some notebooks)
  15. ctypes.windll.winmm.mciSendStringW("set cdaudio door closed",
  16. None, 0, None)
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC