3

I need to send a large JSON file from Node to Python. I can create the child_process with spawn to call the Python file, but I can't work out how to send the data to it. I've tried using pipe, but I'm not understanding the documentation.

Code:

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();

Error:

Uncaught Error: ENAMETOOLONG: name too long, open [file data printed to console here]
2
  • You should set up some listeners on events to handle the stream errors and when the stream ends. Commented Sep 12, 2016 at 11:52
  • lukeramsey.io/child Commented Sep 12, 2016 at 12:26

1 Answer 1

3

Here is a pretty good guide on what you are trying to do!

Seems like you also should do py.stdin.write('json data');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.