Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I eject the CD drive in node.js?

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?

like image 290
Peter Olson Avatar asked Sep 07 '12 23:09

Peter Olson


2 Answers

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 command: http://linux.about.com/od/commands/l/blcmdl1_eject.htm

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

"C:\nircmd.exe cdrom open d:" 
like image 75
MaxPRafferty Avatar answered Oct 07 '22 09:10

MaxPRafferty


In linux you could use nodejs to call the eject command 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?

like image 32
Stuart Wakefield Avatar answered Oct 07 '22 08:10

Stuart Wakefield