refactor(socket) add condition on cd error

This commit is contained in:
coderaiser 2013-07-11 15:27:08 +00:00
parent a95acf668b
commit e9f26a021e

View file

@ -96,7 +96,7 @@
function onMessage(pConnNum, pSocket){
return function(pCommand) {
var lMsg, lJSON, lWinCommand, lExec_func, lDir,
lHome, lError;
lHome, lError, lRet;
Util.log('#' + pConnNum + ': ' + pCommand);
@ -139,7 +139,9 @@
process.chdir(lDir);
});
if (lError) {
if (!lError)
lRet = true;
else {
lJSON = {
stderr: Util.stringifyJSON( lError )
};
@ -150,23 +152,25 @@
}
}
/* if we on windows and command is build in
* change code page to unicode becouse
* windows use unicode on non English versions
*/
if(WIN32){
lWinCommand = pCommand.toUpperCase();
if (!lRet) {
/* if we on windows and command is build in
* change code page to unicode becouse
* windows use unicode on non English versions
*/
if(WIN32){
lWinCommand = pCommand.toUpperCase();
if( Win32Commands.indexOf(lWinCommand) >= 0 )
pCommand = 'chcp 65001 |' + pCommand;
}
if( Win32Commands.indexOf(lWinCommand) >= 0 )
pCommand = 'chcp 65001 |' + pCommand;
if(!ClientFuncs[pConnNum])
ClientFuncs[pConnNum] = getExec(pSocket, pConnNum);
lExec_func = ClientFuncs[pConnNum];
exec(pCommand, lExec_func);
}
if(!ClientFuncs[pConnNum])
ClientFuncs[pConnNum] = getExec(pSocket, pConnNum);
lExec_func = ClientFuncs[pConnNum];
exec(pCommand, lExec_func);
};
}
@ -177,19 +181,27 @@
*/
function getExec(pSocket, pConnNum){
return function(pError, pStdout, pStderr) {
var lErrorJSON = pStderr || pError,
lError = lErrorJSON && Util.stringifyJSON( lErrorJSON ),
lExec = {
stdout : pStdout,
stderr : lError
},
var lErrorStr, lExecStr, lExec,
lError = pStderr || pError;
lExec_str = JSON.stringify(lExec);
if (lError)
if ( Util.isString(lError) )
lErrorStr = lError;
else
lErrorStr = Util.stringifyJSON( lError );
lExec = {
stdout : pStdout,
stderr : lError
};
lExecStr = JSON.stringify(lExec);
log(pConnNum, pError, 'error');
log(pConnNum, pStderr, 'stderror');
pSocket.send(lExec_str);
pSocket.send(lExecStr);
};
}