From 67a3a3bd78026dae2fc3a159fc75ca05481a5f1c Mon Sep 17 00:00:00 2001 From: yczpf2019 Date: Sat, 24 Jan 2026 21:23:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(shell-arduino):=20=E6=94=B9=E7=94=A8=20exec?= =?UTF-8?q?FileUntilClosed=20=E9=81=BF=E5=85=8D=20shell=20=E5=BC=95?= =?UTF-8?q?=E5=8F=B7=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/shell-arduino.js | 68 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/common/shell-arduino.js b/src/common/shell-arduino.js index d7028eab..ec36784b 100755 --- a/src/common/shell-arduino.js +++ b/src/common/shell-arduino.js @@ -12,50 +12,56 @@ export default class ShellArduino extends Shell { let arduino = _.merge({}, ARDUINO); arduino = _.merge(arduino, config); - // 为每个 library 路径生成单独的 --library 参数 - const libraryArgs = arduino.path.libraries - .map(lib => `--library "${lib}"`) - .join(' '); - - const command = [ - `"${arduino.path.cli}"`, + // 构建参数数组,避免 shell 解析引号问题 + const args = [ 'compile', '-b', arduino.key, - '--config-file', `"${arduino.path.config}"`, - '--verbose', - libraryArgs, - '--build-path', `"${arduino.path.build}"`, - '--output-dir', `"${arduino.path.output}"`, - `"${arduino.path.code}"`, + '--config-file', arduino.path.config, + '--verbose' + ]; + + // 为每个 library 路径添加参数 + for (const lib of arduino.path.libraries) { + args.push('--library', lib); + } + + args.push( + '--build-path', arduino.path.build, + '--output-dir', arduino.path.output, + arduino.path.code, '--no-color' - ].join(' '); - console.log('DEBUG ARDUINO COMPILE CMD:', command); - return this.execUntilClosed(command, { maxBuffer: 4096 * 1000000 }); + ); + + console.log('DEBUG ARDUINO COMPILE:', arduino.path.cli, args); + return this.execFileUntilClosed(arduino.path.cli, args, { maxBuffer: 4096 * 1000000 }); } async upload(config) { let arduino = _.merge({}, ARDUINO); arduino = _.merge(arduino, config); - // 为每个 library 路径生成单独的 --library 参数 - const libraryArgs = arduino.path.libraries - .map(lib => `--library "${lib}"`) - .join(' '); - - const command = [ - `"${arduino.path.cli}"`, + // 构建参数数组,避免 shell 解析引号问题 + const args = [ 'compile', '--upload', '-p', arduino.port, '-b', arduino.key, - '--config-file', `"${arduino.path.config}"`, - '--verbose', - libraryArgs, - '--build-path', `"${arduino.path.build}"`, - '--output-dir', `"${arduino.path.output}"`, - `"${arduino.path.code}"`, + '--config-file', arduino.path.config, + '--verbose' + ]; + + // 为每个 library 路径添加参数 + for (const lib of arduino.path.libraries) { + args.push('--library', lib); + } + + args.push( + '--build-path', arduino.path.build, + '--output-dir', arduino.path.output, + arduino.path.code, '--no-color' - ].join(' '); - return this.execUntilClosed(command, { maxBuffer: 4096 * 1000000 }); + ); + + return this.execFileUntilClosed(arduino.path.cli, args, { maxBuffer: 4096 * 1000000 }); } } \ No newline at end of file