1,105,625 Community Members

Handling CD Drives from python

Member Avatar
a1eio
Junior Poster
140 posts since Aug 2005
Reputation Points: 16 [?]
Q&As Helped to Solve: 32 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
coder_gus
Newbie Poster
9 posts since Sep 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
a1eio
Junior Poster
140 posts since Aug 2005
Reputation Points: 16 [?]
Q&As Helped to Solve: 32 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 57 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 0 [?]
 
0
 

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

import pygame.cdrom as cdrom
cdrom.init()
cd = cdrom.CD(0) # 0 = first cdrom device
cd.init()
cd.eject()
cd.quit()
cdrom.quit()

or here's something i found GNU CD Input and Control Library . you can try it out.

Member Avatar
myle
Newbie Poster
21 posts since Jul 2008
Reputation Points: 1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

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/

Member Avatar
Stefano Mtangoo
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 441 [?]
Q&As Helped to Solve: 394 [?]
Skill Endorsements: 2 [?]
 
0
 

on windows use os.system("YOUR EJECT COMMAND HERE")

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

Here is one that works on Windows machines with Python3 ...

# open and close the CD tray door (Windows OS)
# tested with Python 3.1

import ctypes
import time

# open the CD tray door
ctypes.windll.winmm.mciSendStringW("set cdaudio door open",
    None, 0, None)

# wait 3.5 seconds
time.sleep(3.5)

# close the CD tray (manual closing only with some notebooks)
ctypes.windll.winmm.mciSendStringW("set cdaudio door closed",
    None, 0, None)
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article