我正在尝试在节点脚本中运行以下命令:
/bin/sh -c '/Users/edwardthompson/IdeaProjects/evidentia4/evidentia4/package/macosx/e/wkhtmltopdf --page-size "letter" --footer-center "[page] of [topage]" --footer-left "Prepared Jul 7, 2019 by Edward A Thompson" --footer-right "Evidentia(c) 2012-2017" --footer-font-size "10" --footer-font-name "Times" --print-media-type /var/folders/45/2rx5vf4j47jf4hx5157q4q800000gn/T/ResearchSummaryReport-201967122421963.html /var/folders/45/2rx5vf4j47jf4hx5157q4q800000gn/T/ResearchSummaryReport-201967122421964.pdf'
从命令行运行,它可以正常工作,但是我必须对所有传递给/ bin / sh -c的引号
当我在节点脚本中执行相同的操作时:
child = child_process.spawn('/bin/sh -c', ["'" + args.join(' ') + "'"], {stdio: 'inherit'});
我得到:
Message:
Uncaught exception: Error: spawn /bin/sh -c ENOENT
Stack:
error properties: Object({ errno: 'ENOENT', code: 'ENOENT', syscall: 'spawn /bin/sh -c', path: '/bin/sh -c', spawnargs: [ ''/Users/edwardthompson/IdeaProjects/evidentia4/evidentia4/package/macosx/e/wkhtmltopdf --page-size "letter" --footer-center "[page] of [topage]" --footer-left "Prepared Jul 7, 2019 by Edward A Thompson" --footer-right "Evidentia(c) 2012-2017" --footer-font-size "10" --footer-font-name "Times" --print-media-type /var/folders/45/2rx5vf4j47jf4hx5157q4q800000gn/T/ResearchSummaryReport-20196712254722.html /var/folders/45/2rx5vf4j47jf4hx5157q4q800000gn/T/ResearchSummaryReport-20196712254722.pdf'' ] })
Error: spawn /bin/sh -c ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:74:11)
想不通这个...
最佳答案
child_process.spawn正在寻找路径“ / bin / sh -c”的文件,该文件不存在。您应该改为将-c作为参数传递。
尝试这个:
child = child_process.spawn('/bin/sh', ["-c","'" + args.join(' ') + "'"], {stdio: 'inherit'});
关于javascript - node.js脚本中的child_process.spawn ENOENT问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56924115/