2

I'm trying to use something like ioctl(fd, CDROMEJECT, 0), but I don't know how to get the fd referring to the CDROM in the first place.

I've looked into /dev and /Volumes and found nothing related.

Is there any other way to execute the ejection?

4

1 回答 1

5

您是否尝试过使用系统调用?

Mac OS X

例如。在你的终端试试这个

python -c 'import os; os.system("drutil tray open")'

我刚刚在我的 MacBook Pro 上试过这个,如果这有帮助,请告诉我!

代码:

import os

os.system("drutil tray open")

资料来源: http: //osxdaily.com/2007/03/26/quick-tip-eject-media-from-the-command-line/

Linux

import os

os.system("eject -t cdrom")

来源: http: //opentechlab.blogspot.com/2009/06/play-with-cdrom-in-linux.html

视窗

使用“cytpes”模块:

import ctypes, time

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

# try closing the tray
ctypes.windll.winmm.mciSendStringW("set cdaudio door closed", None, 0, None)

资料来源:http ://www.daniweb.com/software-development/python/threads/72834/handling-cd-drives-from-python

普遍的

使用“pygame”模块:在这里下载

import pygame.cdrom as cdrom

cdrom.init()
cd = cdrom.CD(0)
cd.init()
cd.eject()
cd.quit()
cdrom.quit()

来源:http ://bytes.com/topic/python/answers/614751-help-controlling-cdrom-python

使用“pymedia”模块:在这里下载

文档: http: //www.pygame.org/docs/ref/cdrom.html

http://pymedia.org/docs/pymedia.removable.cd.html

库中似乎有一个“弹出”功能:

弹出()弹出或打开光盘驱动器弹出()->无这将打开光盘驱动器并弹出光盘。如果驱动器正在播放或暂停,它将被停止。

来源: http: //www.pygame.org/docs/ref/cdrom.html#pygame.cdrom.CD.eject

问候,

于 2013-09-06T02:49:51.170 回答