从命令行,我有:
sh -c "pdfinfo '/tmp/temp.pdf' | grep Pages: | awk '{print \$2}'"
返回
3
在Node.js中我有相关的
const command = "pdfinfo '" + file + "' | grep Pages: | awk '{print \\$2}'";
const pdfInfo = spawn("sh", ["-c", "\"" + command + "\""]);
pdfInfo.stderr.on("data", (data) => {
console.log(`stderr: ${data}`);
});
当我尝试执行spawn命令时,我得到了
stderr: sh: pdfinfo '/tmp/temp.pdf' | grep Pages: | awk '{print $2}': No such file or directory
为什么我收到此错误消息?