Node.js:使用spawn将图像作为base64传递给python

问题描述 投票:1回答:1

我正在尝试将图像作为base64传递给python,以便使用spawn进行处理,如下所示:

return new Promise(function(resolve, reject) {
      const pythonProcess = spawn('python',["./python.py", imageDataURI]);
      pythonProcess.stdout.on('data', (response) => {
        resolve(response);
      });
    });

但是我得到了error: Error: spawn E2BIG我想它太大了,不能通过它,任何其他方式将它传递给产生?

似乎相关:

Node / child_process throwing E2BIG

node.js python-3.x base64 spawn
1个回答
1
投票

感谢ottomeister的回答,我这样做了:

饮酒,因为:

const pythonProcess = spawn('python',["script.py"]);

pythonProcess.stdin.write(data);
pythonProcess.stdin.end();
pythonProcess.stdout.on('data', (result) => {
    handleResult(result);
});

在python中:

import fileinput

for line in fileinput.input():
    input +=line

# Process input

sys.stdout.write(result)
sys.stdout.flush()
© www.soinside.com 2019 - 2024. All rights reserved.