Search code examples
javascriptnode.jsbashpandocchild-process

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


I'm trying to use execa to convert stdin to a docx file. The promise I await is hanging and never completes. I've tried terminating stdin with a \n, but that doesn't work.

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

Solution

  • Okay I got it. Node writable streams have a end() method.

    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