From cc48c524276ad4962da71e2f25cb5fefd3009237 Mon Sep 17 00:00:00 2001 From: liuhuihao <1061036802@qq.com> Date: Mon, 10 Sep 2018 15:10:16 +0800 Subject: [PATCH] fix: ping encoding(#2) fixed #2 --- package.json | 2 +- src/renderer/pages/hostEdit/index.vue | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e59cb96..9f14a67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d-tools", - "version": "0.1.2", + "version": "0.1.3", "author": "liuhuihao <1061036802@qq.com>", "description": "d-tools is a toolbox for developers.Formatter, Base64, Regex test,Host manager and so on.", "license": "MIT", diff --git a/src/renderer/pages/hostEdit/index.vue b/src/renderer/pages/hostEdit/index.vue index 270d5e3..f976003 100644 --- a/src/renderer/pages/hostEdit/index.vue +++ b/src/renderer/pages/hostEdit/index.vue @@ -92,7 +92,6 @@ import readline from 'readline'; import {Loading} from 'element-ui'; import {exec} from 'child_process'; - import iconv from 'iconv-lite'; import kill from 'tree-kill'; import {copyToClipboard} from '@/utils'; @@ -123,12 +122,12 @@ this.pingStatus = true; if (this.pingIp.trim() != "") { if (process.platform === 'darwin' || process.platform === 'linux') { - this.pingProcess = exec(`ping ${this.pingIp}`, {encoding: 'binary'}); + this.pingProcess = exec(`ping ${this.pingIp}`, {encoding: 'UTF-8'}); } else { - this.pingProcess = exec(`ping ${this.pingIp} -t`, {encoding: 'binary'}); + this.pingProcess = exec(`@chcp 65001 >nul & ping ${this.pingIp} -t`, {encoding: 'UTF-8'}); } this.pingProcess.stdout.on('data', (data) => { - this.pingResult += `${iconv.decode(new Buffer(data, 'binary'), 'cp936')}\n`; + this.pingResult += data; }); this.pingProcess.on('close', (code) => { this.pingStatus = false;