Skip to content

Instantly share code, notes, and snippets.

Created February 4, 2014 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8797615 to your computer and use it in GitHub Desktop.
Save anonymous/8797615 to your computer and use it in GitHub Desktop.
var exec = require('child_process').exec;
function wew(){
exec("iwlist wlan2 scan|grep -Po '(?<=Address: )\\S+|(?<=Signal level=)\\S+|(?<=ESSID:\")[^\"]+'", test);
}
function test(error, stdout, stderr) {
var out = stdout.replace(/^\s+/mg, '');
out = out.split('\n');
var cells = [];
var line;
var info = {};
for (var i=0,l=out.length-1,m=1; i<l; i++,m++) {
line = out[i];
if(i%3 == 0 && i!=0){
cells.push(info);
info = {};
}
if(m%3==1) { info['mac'] = line; }
else if(m%3==2) { info['signal'] = line; }
else if(m%3==0) { info['essid'] = line; }
}
cells.push(info);
// console.log(cells);
for (var i in cells) {
// console.log("the array: " + cells[i].mac); //"aa", bb", "cc"
}
return cells;
}
exports.command = wew;
var reader = require( './file1.js' );
var bang = reader.command();
console.log(bang);
@aredridel
Copy link

file1.js, line 32: Return to where? exec calls it -- and ignores the return value. You need to pass the value forward, in a callback to your original code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment