我正在将文档转换为内存中的pdf(unoconv)并在终端中打印(pdftotext): unoconv -f pdf --stdout sample.doc | pdftotext -layout -enc UTF-8 - out.txt 工作中.现在我想在child_process.spawn中使用此命令: let filePat
unoconv -f pdf --stdout sample.doc | pdftotext -layout -enc UTF-8 - out.txt
工作中.现在我想在child_process.spawn中使用此命令:
let filePath = "...",
process = child_process.spawn("unoconv", [
"-f",
"pdf",
"--stdout",
filePath,
"|",
"pdftotext",
"-layout",
"-enc",
"UTF-8",
"-",
"-"
]);
在这种情况下,只有第一个命令(在|之前)正在工作.我有可能做我正在尝试的事情吗?
谢谢.
最新情况:
结果:sh -c- ….
bash-3.2$sh -c- unoconv -f pdf --stdout /Users/fatimaalves/DEV/xx/_input/sample.doc | pdftotext -layout -enc UTF-8 - -
sh: --: invalid option
Usage: sh [GNU long option] [option] ...
sh [GNU long option] [option] script-file ...
GNU long options:
--debug
--debugger
--dump-po-strings
--dump-strings
--help
--init-file
--login
--noediting
--noprofile
--norc
--posix
--protected
--rcfile
--restricted
--verbose
--version
--wordexp
Shell options:
-irsD or -c command or -O shopt_option (invocation only)
-abefhkmnptuvxBCHP or -o option
Syntax Warning: May not be a PDF file (continuing anyway)
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't read xref table
从管道开始的一切都不是unoconv的参数.它由shell处理,而不是由unoconv处理.所以你不能把它作为unoconv中参数数组的一部分传递.
根据您的需要,有很多方法可以解决这个问题.如果您知道将仅在类UNIX操作系统上运行,则可以将命令作为参数传递给sh:
process = child_process.spawn('sh', ['-c', 'unoconv -f pdf --stdout sample.doc | pdftotext -layout -enc UTF-8 - out.txt']);
