2016-09-12 10 views
2

NodeからPythonに大きなJSONファイルを送信する必要があります。私は、Pythonファイルを呼び出すために、spawnを使ってchild_processを作成することができますが、データをどのように送信するかは分かりません。私はパイプを使ってみましたが、ドキュメントを理解していません。NodeJSからPythonに大きなJSON文字列を送信

コード:

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] 
+0

を行う必要がありますようにあなたは、ストリームのエラーを処理するためにイベントのいくつかのリスナーを設定する必要がありますし、ストリームが終了したときに思えます。 –

+0

http://lukeramsey.io/child – Hitmands

答えて

2

Hereあなたがやろうとしているものにかなり良いガイドです!

はあなたにもpy.stdin.write('json data');

+0

完璧、ありがとう! –

関連する問題