因此,我正在使用Child_process spawn来发送和接收来自NodeJS和Python的数据.
以下是我的代码
var py = spawn('python3', ['./python.py']),
var responseArray = []
py.stdin.write(JSON.stringify(sendData));
py.stdin.end();
py.stdout.on('data', function (data) {
responseArray = JSON.parse(data.toString())
});
py.stdout.on('end', function () {
console.log(responseArray)
});
因此,在代码中,我展示了如果我像这样直接运行node project.js,我会接收到python发送给NodeJS的数据,但是如果我像这样从父文件夹node folder/project.js运行,它将立即转到stdout,显示数据为空