944,221 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 5366
  • Python RSS
Mar 20th, 2007
0

Handling CD Drives from python

Expand Post »
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
Similar Threads
Reputation Points: 26
Solved Threads: 24
Junior Poster
a1eio is offline Offline
140 posts
since Aug 2005
Mar 20th, 2007
0

Re: Handling CD Drives from python

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
coder_gus is offline Offline
9 posts
since Sep 2005
Mar 21st, 2007
0

Re: Handling CD Drives from python

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
Reputation Points: 26
Solved Threads: 24
Junior Poster
a1eio is offline Offline
140 posts
since Aug 2005
Mar 21st, 2007
0

Re: Handling CD Drives from python

Click to Expand / Collapse  Quote originally posted by a1eio ...
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
Python Syntax (Toggle Plain Text)
  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.
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006
Sep 3rd, 2009
0

Re: Handling CD Drives from python

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/
Reputation Points: 11
Solved Threads: 2
Newbie Poster
myle is offline Offline
21 posts
since Jul 2008
Sep 4th, 2009
0

Re: Handling CD Drives from python

on windows use os.system("YOUR EJECT COMMAND HERE")
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Sep 4th, 2009
0

Re: Handling CD Drives from python

Here is one that works on Windows machines with Python3 ...
python Syntax (Toggle Plain Text)
  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)
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: help? - dictionary search problem
Next Thread in Python Forum Timeline: Beginners help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC