-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShellCommand.js
More file actions
64 lines (56 loc) · 1.58 KB
/
ShellCommand.js
File metadata and controls
64 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* **************************************************************************
Additional Command to Execute Shell Command from BASIC
Joe Nicholson Rufilla Ltd.
**************************************************************************
*/
var statements = require('../statements');
var SyntaxError = require('../SyntaxError');
var rl = require('../../IOInterface').getDefault();
var exec = require('child_process').exec;
/**
* Shells execution
*
* @param {String} args The arguments to the command
* @param {Function} define
* @constructor
*/
function ShellCommand(args, define) {
if (args.length) {
this.message = new statements.ExpressionStatement(args, define);
if (this.message.error) throw this.message.error;
} else this.message = new statements.StringStatement("[<< Shelld, Press RETURN to Continue >>]");
}
/**
* Converts the command arguments to a string
*
* @returns {string}
*/
ShellCommand.prototype.toString = function() {
return this.message.toString();
};
/**
* Converts the command to JSON
*
* @returns {Object}
*/
ShellCommand.prototype.toJSON = function() {
return {
message: this.message.toJSON()
};
};
/**
* Executes the command
*
* @param {ExecutionContext} data
* @param {Function} next
*/
ShellCommand.prototype.execute = function(data, next) {
var message = this.message.execute(data);
data.validate(message, 'string');
// Executre the shell command
exec(message, function (error, stdout, stderr) {
console.log(stdout);
next();
});
};
module.exports = ShellCommand;