Atom gpp编译错误:在cwd中的Nodejs child_process.spawn空格

时间:2017-12-13 13:34:05

标签: c++ node.js atom-editor spawn

我刚刚安装了编辑器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)中的空格来完成这项工作吗?

1 个答案:

答案 0 :(得分:0)

我找到了修复程序。在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
  });