簡體   English   中英

將大型 JSON 字符串從 NodeJS 發送到 Python

[英]Send large JSON string from NodeJS to Python

我需要將一個大型 JSON 文件從 Node 發送到 Python。 我可以用 spawn 創建 child_process 來調用 Python 文件,但我不知道如何將數據發送給它。 我試過使用管道,但我不理解文檔。

代碼:

var dataset = JSON.stringify(doc.data);

// Call the python API
try {
  var py = require('child_process').spawn('python3', ['api.py', analysis, input]);
} catch(error) {
  console.log(error);
}

// Pipe the data to the Python module
py.stdin.pipe(fs.createWriteStream(dataset));
py.stdin.end();

錯誤:

Uncaught Error: ENAMETOOLONG: name too long, open [file data printed to console here]

是關於您正在嘗試做什么的非常好的指南!

好像你也應該做py.stdin.write('json data');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM