mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactor(socket) getSpawn
This commit is contained in:
parent
d5ff2471a4
commit
4b9a0016c2
1 changed files with 8 additions and 6 deletions
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
io = main.require('socket.io'),
|
||||
update = main.srvrequire('update'),
|
||||
|
||||
exec = main.child_process.exec,
|
||||
spawn = main.child_process.spawn,
|
||||
|
||||
Util = main.util,
|
||||
path = main.path,
|
||||
mainpackage = main.mainpackage,
|
||||
|
|
@ -236,12 +239,11 @@
|
|||
}
|
||||
|
||||
function getSpawn(pCommand, options, callback) {
|
||||
var send, cmd, spawn,
|
||||
var send, cmd,
|
||||
args = pCommand.split(' ');
|
||||
|
||||
pCommand = args.shift();
|
||||
|
||||
spawn = main.child_process.spawn;
|
||||
Util.tryCatchLog(function() {
|
||||
cmd = spawn(pCommand, args, options);
|
||||
});
|
||||
|
|
@ -249,19 +251,19 @@
|
|||
if (cmd) {
|
||||
send = function(error, data) {
|
||||
var exec = {
|
||||
stderr: error + '',
|
||||
stdout: data + ''
|
||||
stderr: error,
|
||||
stdout: data
|
||||
};
|
||||
|
||||
Util.exec(callback, exec);
|
||||
};
|
||||
|
||||
cmd.stdout.on('data', function(data) {
|
||||
send(null, data);
|
||||
send(null, data + '');
|
||||
});
|
||||
|
||||
cmd.stderr.on('data', function(error) {
|
||||
send(error);
|
||||
send(error + '', null);
|
||||
});
|
||||
|
||||
cmd.on('error', Util.retFalse);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue