Using two commands (using pipe |) with spawn

偶尔善良 提交于 2019-12-06 03:54:22

Everything starting with the pipe is not an argument to unoconv. It is processed by the shell, not by unoconv. So you can't pass it as part of the argument array in unoconv.

There are a number of ways around this, depending on your needs. If you know you will be running on UNIX-like operating systems only, you can pass your command as an argument to sh:

process = child_process.spawn('sh', ['-c', 'unoconv -f pdf --stdout sample.doc | pdftotext -layout -enc UTF-8 - out.txt']);

If you don't want to use the sh command as explained above, you must create multiple child_process.spawn instances and then pipe them into each other like so:

const getModule = spawn('curl', [url, '-ks']);
const unTar = spawn('tar', ['-xvz', '-C', fileName, '--strip-components', 1]);
getModule.stdout.pipe(unTar.stdin);

The above code theoretically will retrieve a tar from url, and unpack into a directory fileName

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!