Skip to content

Commit

Permalink
added timeout support
Browse files Browse the repository at this point in the history
  • Loading branch information
NAlexandrov committed Jul 23, 2015
1 parent 8afba65 commit 8ae88a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/wmic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var wmic = function (options) {
this.username = getUsername(options.username);
this.password = options.password;
this.namespace = options.namespace || '\\\\root\\cimv2';
this.timeout = options.timeout || 90000;
this.delimiter = '^@^';
this.wmic = options.wmic || 'wmic';
this.isWindows = process.platform === 'win32';
Expand Down Expand Up @@ -120,6 +121,7 @@ wmic.prototype.query = function (wql, namespace, callback) {
*/
wmic.prototype._exec = function (callback) {
var self = this;

var wmic = spawn(this.wmic, this._getArgs(), {
cwd: path.join(__dirname, '..'),
stdio: ['ignore', 'pipe', 'pipe']
Expand All @@ -137,13 +139,22 @@ wmic.prototype._exec = function (callback) {
stderr += data;
});

var to = setTimeout(function () {
stderr = 'Child process killed by timeout (' + self.timeout / 1000 + ' seconds)';
wmic.kill();
}, self.timeout);

wmic.on('close', function (code) {
if (code !== 0) {
callback(new Error('Exit code: ' + code + '. ' + stderr));
} else {
callback(null, parse(stdout, self.parserOptions));
}
});

wmic.on('exit', function () {
clearTimeout(to);
});
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wmi-client",
"version": "0.1.4",
"version": "0.1.5",
"description": "Wrapper around the WMI client. Linux and Windows WMI clients are supported.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8ae88a3

Please sign in to comment.