简体   繁体   English

Node.js execa:如何完成写入进程的标准输入

[英]Node.js execa: how to finish writing to process' stdin

I'm trying to use execa to convert stdin to a docx file.我正在尝试使用 execa 将 stdin 转换为 docx 文件。 The promise I await is hanging and never completes.我等待的承诺悬而未决。 I've tried terminating stdin with a \\n , but that doesn't work.我试过用\\n终止 stdin ,但这不起作用。

const process  = execa('pandoc', ['-', '-o', 'file.docx'])
process.stdin.write('input to be made into a docx file')
process.stdin.write('\n')
const result = await process

Okay I got it.好的,我明白了。 Node writable streams have a end() method.节点可写流有一个end()方法。

const process  = execa('pandoc', ['-', '-o', 'file.docx'])
process.stdin.write('input to be made into a docx file')
process.stdin.end();
const result = await process

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM