mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fix(win) getVolumes: add stdin.end
This commit is contained in:
parent
3f7f344d3a
commit
7dac169e12
1 changed files with 57 additions and 43 deletions
|
|
@ -1,43 +1,57 @@
|
|||
/*
|
||||
* Library contain windows specific functions
|
||||
* like getting information about volumes
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/* win.js
|
||||
* -----------
|
||||
*
|
||||
* used for work with windows specific
|
||||
* functions like volumes.
|
||||
*/
|
||||
|
||||
var processExec = require('child_process').exec,
|
||||
DIR = '../',
|
||||
Util = require(DIR + 'util');
|
||||
|
||||
exports.getVolumes = getVolumes;
|
||||
|
||||
function getVolumes(callback) {
|
||||
processExec('wmic logicaldisk get name', function(error, stdout, stderr) {
|
||||
var volumes = [],
|
||||
removeStr = [
|
||||
'\r', '\n',
|
||||
'Name', ' ',
|
||||
];
|
||||
|
||||
if (!error)
|
||||
error = stderr;
|
||||
|
||||
if(!error) {
|
||||
volumes = Util.rmStr(stdout, removeStr)
|
||||
.split(':');
|
||||
|
||||
volumes.pop();
|
||||
}
|
||||
|
||||
Util.exec(callback, error, volumes);
|
||||
});
|
||||
}
|
||||
})();
|
||||
/*
|
||||
* Library contain windows specific functions
|
||||
* like getting information about volumes
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/* win.js
|
||||
* -----------
|
||||
*
|
||||
* used for work with windows specific
|
||||
* functions like volumes.
|
||||
*/
|
||||
|
||||
var spawn = require('child_process').spawn,
|
||||
DIR = '../',
|
||||
DIR_SERVER = DIR + 'server/',
|
||||
Util = require(DIR + 'util'),
|
||||
pipe = require(DIR_SERVER + 'pipe');
|
||||
|
||||
exports.getVolumes = getVolumes;
|
||||
|
||||
function getVolumes(callback) {
|
||||
var wmic = spawn('wmic', ['logicaldisk', 'get', 'name']);
|
||||
|
||||
/* stream should be closed on win xp*/
|
||||
wmic.stdin.end();
|
||||
|
||||
pipe.getBody(wmic.stdout, function(error, data) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
parse(data, callback);
|
||||
});
|
||||
|
||||
wmic.stderr.on('data', callback);
|
||||
wmic.on('error', callback);
|
||||
}
|
||||
|
||||
function parse(data, callback) {
|
||||
var volumes = [],
|
||||
strDrop = [
|
||||
'\r', '\n',
|
||||
'Name', ' ',
|
||||
];
|
||||
|
||||
if (data) {
|
||||
volumes = Util.rmStr(data, strDrop)
|
||||
.split(':');
|
||||
|
||||
volumes.pop();
|
||||
}
|
||||
|
||||
callback(null, volumes);
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue