Force node.js to use bin/bash instead of sh

主宰稳场 提交于 2019-12-11 02:49:22

问题


I'm trying to execute a basic bash script from node using the exec() function. The bash script is as follows:

#!/bin/bash
ffmpeg -f concat -i <(for f in $1/*.mov ; do echo "file '$f'"; done) -c copy $1/output.mov

The script works fine running it from the command line but when running from within node I get a syntax error: line 2: syntax error near unexpected token('`

It appears when running this command node it attempting to use sh instead of bash. Can anyone verify this is true and give a possible workaround or solution? Thanks ahead of time!


回答1:


Try child_process.execFile or just explicitly run ['/bin/bash', '/path/to/your/script.sh', arg1, arg2...].




回答2:


Provided you're on a recent version of Node, you can add the following as option for exec:

{shell: "/bin/bash"}

See: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback



来源:https://stackoverflow.com/questions/19460928/force-node-js-to-use-bin-bash-instead-of-sh

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