Skip to content

Instantly share code, notes, and snippets.

@flexd
Created October 8, 2012 16:43
Show Gist options
  • Save flexd/3853512 to your computer and use it in GitHub Desktop.
Save flexd/3853512 to your computer and use it in GitHub Desktop.
var spawn = require('child_process').spawn,
ls = spawn('pcsc_scan', []);
var util = require('util');
var atrfound = false;
console.log("pcsc_scan should be running now");
ls.stdout.on('data', function (data) {
//console.log('stdout: ' + data);
var data = data.toString();
data = data.replace(/\u001b\[\d{0,2}m/g, ''); // Remove ANSI colors.
var state = /Card state: Card (.+),/.exec(data);
if (state) {
state = state[1];
if (state == "inserted") {
}
if (state == "removed") {
atrfound = false;
}
console.log("Card state is: " + state);
}
// lets try to read a UID.
var atr = /ATR: (.+)/.exec(data);
if (atr && !atrfound) {
atr = atr[1];
atrfound = true;
console.log("ATR: " + atr);
}
});
ls.stderr.on('data', function (data) {
//console.log('stderr: ' + data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment