feature(socket) add chdir on cd

This commit is contained in:
coderaiser 2013-07-11 08:12:54 +00:00
parent b52d06bbaa
commit 0ad307d867
2 changed files with 25 additions and 4 deletions

View file

@ -106,6 +106,8 @@ getJSONfromFileTable.
* feature(util) add logArray
* feature(socket) add chdir on cd
2012.04.22, v0.2.0

View file

@ -95,7 +95,8 @@
*/
function onMessage(pConnNum, pSocket){
return function(pCommand) {
var lMsg, lWinCommand, lExec_func;
var lMsg, lJSON, lWinCommand, lExec_func, lDir,
lHome, lError;
Util.log('#' + pConnNum + ': ' + pCommand);
@ -115,20 +116,38 @@
pCommand = 'kill -9 ' + process.pid;
}
else {
lMsg = {
lJSON = {
stdout : CLOUDCMD + ' exit \n' +
CLOUDCMD + ' update \n',
stderr : null
};
lMsg = JSON.stringify(lMsg);
lMsg = Util.stringifyJSON( lJSON );
pSocket.send(lMsg);
Util.log('received from client: ' + pCommand);
Util.log('sended to client: ' + lMsg);
}
} else if( Util.isContainStrAtBegin(pCommand, 'cd ') ) {
pCommand = Util.removeStr(pCommand, 'cd ');
lDir = Util.removeStr(pCommand, 'cd ');
lHome = process.env.HOME;
if ( Util.isContainStr(lDir, '~') )
lDir = Util.replaceStr(lDir, '~', lHome);
lError = Util.tryCatchLog(function(){
process.chdir(lDir);
});
if (lError) {
lJSON = {
stderr: Util.stringifyJSON( lError )
};
lMsg = Util.stringifyJSON( lJSON );
pSocket.send(lMsg);
}
}
/* if we on windows and command is build in