Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 用于Windows和Ubuntu的NodeJS exec()命令_Node.js_Windows_Ubuntu_Npm_Gulp - Fatal编程技术网

Node.js 用于Windows和Ubuntu的NodeJS exec()命令

Node.js 用于Windows和Ubuntu的NodeJS exec()命令,node.js,windows,ubuntu,npm,gulp,Node.js,Windows,Ubuntu,Npm,Gulp,使用NodeJS、NPM和Gulp 我想构建一个gulp任务来运行在Ubuntu和Windows上工作的JSDoc 这在Ubuntu上有效 var exec = require('child_process').exec; return function(cb) { exec('node node_modules/.bin/jsdoc -c jsdoc-conf.json', function(err, stdout, stderr) { cb(err); }); }; 这在

使用NodeJS、NPM和Gulp

我想构建一个gulp任务来运行在Ubuntu和Windows上工作的JSDoc

这在Ubuntu上有效

var exec = require('child_process').exec;

return function(cb) {
  exec('node node_modules/.bin/jsdoc -c jsdoc-conf.json', function(err, stdout, stderr) {
    cb(err);
  });
};
这在Windows上工作

var exec = require('child_process').exec;

return function(cb) {
  exec('node_modules\\.bin\\jsdoc -c jsdoc-conf.json', function(err, stdout, stderr) {
    cb(err);
  });
};

不用说,两者对另一方都不起作用。其他人是如何解决此类问题的?

尝试使用,无论平台如何,它都会为您提供文件的完整路径

节点有
进程.平台
,它。。。“返回一个字符串,标识运行Node.js进程的操作系统平台。例如,
darwin
freebsd
linux
sunos
win32

使用:


如果需要特定的平台类型,我建议使用path.resolve或path.posix.resolve或path.win32.resolvepath@justin.m.chase使用path.resolve重新实现,更干净。谢谢
var exec = require('child_process').exec;

return function(cb) {
  if (process.platform === 'win32') {
    // Windows OS
  } else {
    // everything else
  }
};
const exec = require('child_process').exec;
const path = require('path');

return function(cb) {
  let command = `node ${path.resolve('node_modules/.bin/jsdoc')} -c jsdoc-conf.json`;

  exec(command, function(err, stdout, stderr) {
    cb(err);
  });
};