支持修改环境变量和 ALIAS

This commit is contained in:
fofolee
2022-05-19 00:59:37 +08:00
parent 2dd7508911
commit 1ee35586c1
5 changed files with 102 additions and 25 deletions

View File

@@ -570,11 +570,15 @@ window.runCodeInSandbox = (code, callback, addVars = {}) => {
}
window.runCodeFile = (cmd, option, terminal, callback) => {
var bin = option.bin,
argv = option.argv,
ext = option.ext,
charset = option.charset,
scptarg = option.scptarg || "";
let {
bin,
argv,
ext,
charset,
scptarg,
envPath,
alias
} = option
let script = getQuickcommandTempFile(ext, 'quickcommandTempScript');
// 批处理和 powershell 默认编码为 GBK, 解决批处理的换行问题
if (charset.scriptCode) cmd = iconv.encode(cmd.replace(/\n/g, '\r\n'), charset.scriptCode);
@@ -598,11 +602,15 @@ window.runCodeFile = (cmd, option, terminal, callback) => {
} else {
cmdline = `${bin} ${argv} "${script}" ${scptarg}`
}
let processEnv = _.cloneDeep(process.env);
if (envPath) processEnv.PATH = envPath;
if (alias) cmdline = alias + '\n' + cmdline;
// 在终端中输出
if (terminal) cmdline = getCommandToLaunchTerminal(cmdline)
child = child_process.spawn(cmdline, {
encoding: 'buffer',
shell: true
shell: true,
env: processEnv
});
// var chunks = [],
// err_chunks = [];