mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactor(win) processOutput
This commit is contained in:
parent
c4310904d7
commit
1e5a8ae82b
1 changed files with 26 additions and 27 deletions
|
|
@ -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);
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue