From 8f6892c59f9644cd613187af467bfafd769d0372 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 1 Jul 2014 09:29:24 -0400 Subject: [PATCH] feature(console) change console output on windows --- cloudcmd.js | 3 +++ lib/server/console.js | 33 ++++----------------------------- lib/server/win.js | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/cloudcmd.js b/cloudcmd.js index 141849c4..b466ed1a 100644 --- a/cloudcmd.js +++ b/cloudcmd.js @@ -23,6 +23,8 @@ Minify = main.minify, Config = main.config, + win = require(DIR_SERVER + 'win'), + CONFIG_PATH = JSONDIR + 'config.json', KEY = DIR + 'ssl/ssl.key', @@ -47,6 +49,7 @@ DIR = main.DIR; readConfig(init); + win.prepareCodePage(); /** * additional processing of index file diff --git a/lib/server/console.js b/lib/server/console.js index 525c0c37..f500f95b 100644 --- a/lib/server/console.js +++ b/lib/server/console.js @@ -29,24 +29,7 @@ HELP = { stdout : CLOUDCMD + ' exit \n' + CLOUDCMD + ' update \n', - }, - - /* windows commands thet require - * unicode charset on locales - * different then English - */ - Win32Commands = ['ASSOC', 'AT', 'ATTRIB', 'BREAK', 'CACLS', 'CALL', - 'CD', 'CHCP', 'CHDIR', 'CHKDSK', 'CHKNTFS', 'CLS', - 'CMD', 'COLOR', 'COMP', 'COMPACT', 'CONVERT', 'COPY', - 'DATE', 'DEL', 'DIR', 'DISKCOMP', 'DISKCOPY', 'DOSKEY', - 'ECHO', 'ENDLOCAL', 'ERASE', 'EXIT', 'FC', 'FIND', - 'FINDSTR', 'FOR', 'FORMAT', 'FTYPE', 'GOTO', 'GRAFTABL', - 'HELP', 'IF', 'LABEL', 'MD', 'MKDIR', 'MODE', 'MORE', - 'MOVE', 'PATH', 'PAUSE', 'POPD', 'PRINT', 'PROMPT', - 'PUSHD', 'RD', 'RECOVER', 'REM', 'REN', 'RENAME', - 'REPLACE', 'RMDIR', 'SET', 'SETLOCAL', 'SHIFT', 'SORT', - 'START', 'SUBST', 'TIME', 'TITLE', 'TREE', 'TYPE', - 'VER', 'VERIFY', 'VOL', 'XCOPY']; + }; /** * function listen on servers port @@ -140,18 +123,10 @@ ClientDirs[connNum] = path; }); } - + if (!ret) { - /* if we on windows and command is build in - * change code page to unicode becouse - * windows use unicode on non English versions - */ - if (WIN32) { - winCommand = command.toUpperCase(); - - if (Win32Commands.indexOf(winCommand) >= 0) - command = 'chcp 65001 |' + command; - } + if (WIN32) + command = 'cmd /C ' + command; if (!ClientFuncs[connNum]) ClientFuncs[connNum] = Util.exec.with(setExec, function(json, error, stderr) { diff --git a/lib/server/win.js b/lib/server/win.js index 12832718..8018fb24 100644 --- a/lib/server/win.js +++ b/lib/server/win.js @@ -14,12 +14,14 @@ */ var spawn = require('child_process').spawn, + exec = require('child_process').exec, DIR = '../', DIR_SERVER = DIR + 'server/', Util = require(DIR + 'util'), pipe = require(DIR_SERVER + 'pipe'); - exports.getVolumes = getVolumes; + exports.getVolumes = getVolumes; + exports.prepareCodePage = prepareCodePage; function getVolumes(callback) { var wmic = spawn('wmic', ['logicaldisk', 'get', 'name']); @@ -56,4 +58,20 @@ callback(null, volumes); } + + function prepareCodePage() { + /* if we on windows and command is build in + * change code page to unicode becouse + * windows use unicode on non English versions + */ + + if (process.platform === 'win32') + exec('chcp 65001', function(error, stdout, stderror) { + if (error) + console.log(error); + + if (stderror) + console.log(stderror); + }); + } })();