mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 22:51:25 +08:00
jschardet判断编码,增加 hostname 判断
This commit is contained in:
parent
6a4cd2f9c8
commit
a2bb06eea2
12
preload.js
12
preload.js
@ -4,6 +4,7 @@ const { spawn, exec } = require("child_process")
|
|||||||
const iconv = require('iconv-lite')
|
const iconv = require('iconv-lite')
|
||||||
const { clipboard } = require('electron')
|
const { clipboard } = require('electron')
|
||||||
const robot = require('./robotjs')
|
const robot = require('./robotjs')
|
||||||
|
const jschardet = require("jschardet")
|
||||||
|
|
||||||
//-------checkUpdate------
|
//-------checkUpdate------
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
@ -144,6 +145,12 @@ special = async cmd => {
|
|||||||
cmd = cmd.replace(/\{\{isWin\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{isWin\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取电脑名
|
||||||
|
if (cmd.includes('{{HostName}}')) {
|
||||||
|
let repl = os.hostname();
|
||||||
|
cmd = cmd.replace(/\{\{HostName\}\}/mg, repl)
|
||||||
|
}
|
||||||
|
|
||||||
// 获取资源管理器或访达当前目录
|
// 获取资源管理器或访达当前目录
|
||||||
if (cmd.includes('{{pwd}}')) {
|
if (cmd.includes('{{pwd}}')) {
|
||||||
let repl = await pwd();
|
let repl = await pwd();
|
||||||
@ -193,12 +200,11 @@ run = async (cmd, option, codec, callback) => {
|
|||||||
}
|
}
|
||||||
var chunks = [],
|
var chunks = [],
|
||||||
err_chunks = [];
|
err_chunks = [];
|
||||||
codec = isWin ? codec : 'utf8';
|
|
||||||
child.stdout.on('data', chunk => {
|
child.stdout.on('data', chunk => {
|
||||||
chunks.push(iconv.decode(chunk, codec))
|
chunks.push(iconv.decode(chunk, jschardet.detect(chunk).encoding))
|
||||||
})
|
})
|
||||||
child.stderr.on('data', err_chunk => {
|
child.stderr.on('data', err_chunk => {
|
||||||
err_chunks.push(iconv.decode(err_chunk, codec))
|
err_chunks.push(iconv.decode(err_chunk, jschardet.detect(err_chunk).encoding))
|
||||||
})
|
})
|
||||||
child.on('close', code => {
|
child.on('close', code => {
|
||||||
let stdout = chunks.join("");
|
let stdout = chunks.join("");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user