最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I eject the CD drive in node.js? - Stack Overflow

programmeradmin0浏览0评论

I'd like to create a small application with node.js that would look something like this:

console.log("Creating extra beer holder...");
EjectCD();

Does such functionality already exist, or will it be necessary to create some sort of C++ binding to do this?

I'd like to create a small application with node.js that would look something like this:

console.log("Creating extra beer holder...");
EjectCD();

Does such functionality already exist, or will it be necessary to create some sort of C++ binding to do this?

Share Improve this question asked Sep 7, 2012 at 23:07 Peter OlsonPeter Olson 143k49 gold badges208 silver badges249 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 5

You can do this by taking advantage of the fact that node.js runs in an environment console. That said, it will only open the drive on your server, and is dependant on your server's OS. The following should (I have no cd drive to test) work in a linux environment where your cd drive is mounted as "cdrom":

console.log("Creating extra beer holder...");
exec("eject cdrom -r");

This page gives more info on the linux eject mand: http://linux.about./od/mands/l/blcmdl1_eject.htm

There is no native windows mand line mand for eject, but there are a number of simple executables you could place on your server to acplish this, for example http://www.nirsoft/utils/nircmd.zip, which would take the mand:

"C:\nircmd.exe cdrom open d:" 

In linux you could use nodejs to call the eject mand line...

var exec = require('child_process').exec;
exec("eject [options]", function (error, stdout, stderr) { ... })

in Windows you need to leverage the Media Control Interface. Unfortunately there doesn't appear to exist anything for NodeJS yet so you may need to port something over or daisy chain using a package in another language. In Lua there is a module written to do it...

Open CD/DVD door with a Windows API call?

There is now an NPM module that can be used to eject the cd drive. Here is the module.

var diskdrive = require('diskdrive');
diskdrive.eject();

Currently it doesn't offer support for Windows, however Linux and Mac are both supported. The library works by just calling the respective mand-line tools necessary to eject the cd drive, while at the same time adding support for different OS's and eliminates callback hell.

发布评论

评论列表(0)

  1. 暂无评论