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?
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:"
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With