首页 > 解决方案 > 使用 node.js 运行 shell 命令

问题描述

我有这个代码:

convert -limit memory 2MB \( /var/www/html/sistema/publico/uploads/3_5_foto_formatada.png /var/www/html/sistema/publico/uploads/3_8_foto_formatada.png /var/www/html/sistema/publico/uploads/3_2_foto_formatada.png +append \) \
\( /var/www/html/sistema/publico/uploads/3_7_foto_formatada.png /var/www/html/sistema/publico/uploads/3_4_foto_formatada.png /var/www/html/sistema/publico/uploads/3_6_foto_formatada.png +append \) \
\( /var/www/html/sistema/publico/uploads/3_6_foto_formatada.png /var/www/html/sistema/publico/uploads/3_6_foto_formatada.png /var/www/html/sistema/publico/uploads/3_6_foto_formatada.png +append \) \
-background none -append /var/www/html/sistema/publico/uploads/3_unidas.png

当我在腻子上运行它时,它工作得很好。

但是当我尝试在 node.js 上运行它时,它给了我一些错误,比如这段代码不正确。

喜欢:

/bin/sh: 2: (: 未找到 /bin/sh: 3: (: 未找到 /bin/sh: 4: -background: 未找到

我包含了这个库: const {execSync} = require('child_process');

我以这种方式运行:

let output = execSync(varWithCommand);

提前致谢!

标签: node.jsshellimagemagickexecnode-modules

解决方案


推荐阅读