From f6d0099212273d64fd2474708d114df181d12f5d Mon Sep 17 00:00:00 2001 From: purocean Date: Wed, 13 Jan 2021 14:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E4=BB=A3=E7=A0=81=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/run.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/server/run.ts b/src/server/run.ts index a7593f4d..5580ed74 100644 --- a/src/server/run.ts +++ b/src/server/run.ts @@ -6,6 +6,7 @@ import * as wsl from './wsl' import config from './config' const isWsl = wsl.isWsl +const isWin = os.platform() === 'win32' const runCode = (language: string, code: string) => { try { @@ -17,7 +18,7 @@ const runCode = (language: string, code: string) => { js: { cmd: 'node', args: ['-e'] }, } as {[key: string]: {cmd: string, args: string[]}} - if (language === 'bat') { + if (language === 'bat' && isWin) { const fileName = 'yn-run-cmd.bat' code = code.split('\n').slice(1).join('\n') // 去掉第一行的注释 if (isWsl) { @@ -36,15 +37,21 @@ const runCode = (language: string, code: string) => { return `不支持 ${language} 语言` } - const useWsl = os.platform() === 'win32' && config.get('runCodeUseWsl', false) + const useWsl = isWin && config.get('runCodeUseWsl', false) if (useWsl) { return execFileSync('wsl.exe', ['--', runParams.cmd].concat(runParams.args).concat([code])).toString() } + const env = { ...process.env } + const extPath = '/usr/local/bin' + if (!isWin && env.PATH.indexOf(extPath) < 0) { + env.PATH = `${extPath}:${env.PATH}` + } + return execFileSync( runParams.cmd, runParams.args.concat([code]), - { env: process.env } + { env } ).toString() } catch (e) { return e.message