refactor(win) processOutput

This commit is contained in:
coderaiser 2014-04-23 08:46:06 -04:00
parent c4310904d7
commit 1e5a8ae82b

View file

@ -4,9 +4,9 @@
*/
(function(){
"use strict";
'use strict';
if(!global.cloudcmd)
if (!global.cloudcmd)
return console.log(
'# win.js' + '\n' +
'# -----------' + '\n' +
@ -24,34 +24,33 @@
exec = main.child_process.exec,
Util = main.util;
exports.getVolumes = function(callback) {
var chcp = 'chcp ' + Charset.UNICODE,
getVolumes = 'wmic logicaldisk get name';
exports.getVolumes = function(pCallBack){
var lCHCP = 'chcp ' + Charset.UNICODE,
lGetVolumes = 'wmic logicaldisk get name';
exec(lCHCP + ' && ' + lGetVolumes, retProcessOuput(pCallBack));
exec(chcp + ' && ' + getVolumes, Util.bind(processOuput, callback));
};
function retProcessOuput(pCallBack){
return function(pError, pStdout, pStderr){
var lRemoveStr = [
'\r', '\n',
'Name',
'Active code page: 65001 '
],
lVolumes = [],
lError = pError || pStderr;
exec('chcp ' + Charset.WIN32);
if(!lError) {
lVolumes = Util.removeStr(pStdout, lRemoveStr)
.split(' ');
lVolumes.pop();
}
function processOuput(callback, error, stdout, stderr) {
var volumes = [],
removeStr = [
'\r', '\n',
'Name',
'Active code page: 65001 '
];
if (!error)
error = stderr;
exec('chcp ' + Charset.WIN32);
if(!error) {
volumes = Util.removeStr(stdout, removeStr)
.split(' ');
Util.exec(pCallBack, lError || lVolumes);
};
volumes.pop();
}
Util.exec(callback, error || volumes);
}
})();