如何用Python从MacOS中弹出CD?

时间:2013-09-06 02:30:55

标签: python macos

我正在尝试使用类似ioctl(fd, CDROMEJECT, 0)的内容,但我不知道如何让fd首先引用CDROM。

我调查了/dev/Volumes,发现没有相关内容。

还有其他方法可以执行ejection吗?

1 个答案:

答案 0 :(得分:5)

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

Mac OS X

EG。在您的终端

中试试这个
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

使用“细胞”模块:

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”模块:Download here

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”模块:Download here

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

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

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

  

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

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

此致