mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-24 03:05:41 +00:00
feature(socket) add spawn
This commit is contained in:
parent
a0a064e985
commit
7bda84f98f
1 changed files with 42 additions and 3 deletions
|
|
@ -120,7 +120,7 @@
|
|||
function onMessage(pConnNum, pSocket) {
|
||||
return function(pCommand) {
|
||||
var lMsg, lJSON, lWinCommand, lExec_func, lDir,
|
||||
lHome, lError, lRet;
|
||||
lHome, lError, lRet, lExecSymbols;
|
||||
|
||||
Util.log('#' + pConnNum + ': ' + pCommand);
|
||||
|
||||
|
|
@ -193,7 +193,12 @@
|
|||
|
||||
lExec_func = ClientFuncs[pConnNum];
|
||||
|
||||
exec(pCommand, lExec_func);
|
||||
lExecSymbols = ['{', '}', '|', '\'', '"'];
|
||||
|
||||
if (Util.isContainStr(pCommand, lExecSymbols))
|
||||
exec(pCommand, lExec_func);
|
||||
else
|
||||
getSpawn(pSocket, pConnNum, pCommand);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -220,7 +225,7 @@
|
|||
stderr : lError
|
||||
};
|
||||
|
||||
lExecStr = JSON.stringify(lExec);
|
||||
lExecStr = JSON.stringify(lExec);
|
||||
|
||||
log(pConnNum, pError, 'error');
|
||||
log(pConnNum, pStderr, 'stderror');
|
||||
|
|
@ -229,6 +234,40 @@
|
|||
};
|
||||
}
|
||||
|
||||
function getSpawn(pSocket, pConnNum, pCommand) {
|
||||
var send, cmd, spawn,
|
||||
args = pCommand.split(' ');
|
||||
|
||||
pCommand = args.shift();
|
||||
|
||||
spawn = main.child_process.spawn;
|
||||
cmd = spawn(pCommand, args);
|
||||
send = function(data, isError) {
|
||||
var lExecStr,
|
||||
lExec = {},
|
||||
msg = data.toString();
|
||||
|
||||
if (isError)
|
||||
lExec.stderr = msg;
|
||||
else
|
||||
lExec.stdout = msg;
|
||||
|
||||
lExecStr = JSON.stringify(lExec);
|
||||
pSocket.send(lExecStr);
|
||||
Util.log(msg);
|
||||
};
|
||||
|
||||
cmd.stdout.on('data', send);
|
||||
|
||||
cmd.stderr.on('data', function(data) {
|
||||
send(data, true);
|
||||
});
|
||||
|
||||
cmd.on('error', function(data) {
|
||||
send(data, true);
|
||||
});
|
||||
}
|
||||
|
||||
function log(pConnNum, pStr, pType) {
|
||||
var lRet, lType = ' ';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue