mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(socket) add chdir on cd
This commit is contained in:
parent
b52d06bbaa
commit
0ad307d867
2 changed files with 25 additions and 4 deletions
|
|
@ -106,6 +106,8 @@ getJSONfromFileTable.
|
|||
|
||||
* feature(util) add logArray
|
||||
|
||||
* feature(socket) add chdir on cd
|
||||
|
||||
|
||||
2012.04.22, v0.2.0
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue