如何在MacOSX和Linux上的节点中启动ChildProcess
我有一个Express服务器,在Linux box上运行下面的脚本。 现在,希望将python文件位置引用更改为a目录结构 在MacOSX上。我需要一些引用节点中当前工作目录的内容,但是 作为相对位置工作。这是一个路径问题。类似的代码在Linux上运行良好如何在MacOSX和Linux上的节点中启动ChildProcess,linux,macos,node.js,express,path,Linux,Macos,Node.js,Express,Path,我有一个Express服务器,在Linux box上运行下面的脚本。 现在,希望将python文件位置引用更改为a目录结构 在MacOSX上。我需要一些引用节点中当前工作目录的内容,但是 作为相对位置工作。这是一个路径问题。类似的代码在Linux上运行良好 app.put('/route', function(req, res){ req.on('end', function () { var child; var values =
app.put('/route', function(req, res){
req.on('end', function () {
var child;
var values = req.body;
var shellScrpt = " python /MyPython.py '"
var shellScrptVar = JSON.stringify(values) + "' " ;
child = childProcess.exec(shellScrpt+shellScrptVar, function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
}
console.log('Child Process STDOUT: '+stdout);
});
res.end();
});
})
在不使用其他要求的情况下解决:
var pwdir = path.resolve(process.cwd(),"../ParentWorkingDir")
var shellScrpt = " python "+ pwdir +"/MyPython.py '"