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