Atom gpp compiling error : Nodejs child_process.spawn whitespace in cwd

Atom gpp compiling error : Nodejs child_process.spawn whitespace in cwd

我刚刚安装了编辑器 Atom 和包 gpp https://github.com/livace/atom-gpp 来编译和 运行 c++。当我 运行 我收到一条错误消息说没有这样的文件或目录。

我认为这是因为我的目录路径中有一个空格。我检查了gpp插件的源代码,发现了这个:

const options = (file.path + ' -o ' + compiledPath + ' ' + atom.config.get('gpp.compilerOptions')).replace(/[\s{2,}]+/g, ' ').trim();

path.join(filePath.dir, filePath.name);

const child = child_process.spawn('g++', options.split(' '), {
  cwd: filePath.dir
});

我以前从未使用过 nodeJs,但我认为这是导致错误的原因。知道如何使用目录路径 (cwd) 中的空格使其工作吗?

我找到了解决方法。在 gpp 插件的 index.js 中,更改

const options = (file.path + ' -o ' + compiledPath + ' ' + atom.config.get('gpp.compilerOptions')).replace(/[\s{2,}]+/g, ' ').trim();

path.join(filePath.dir, filePath.name);
console.log(options.split(' '));
const child = child_process.spawn('g++', options.split(' '), {
  cwd: filePath.dir
});

  const options = atom.config.get('gpp.compilerOptions').replace(/[\s{2,}]+/g, ' ').trim();

  path.join(filePath.dir, filePath.name);
  var new_options = [file.path,'-o',compiledPath]
  if (options != ""){
    new_options = new_options.concat(options.split(' '));
  }
  const child = child_process.spawn('g++', new_options, {
    cwd: filePath.dir
  });