问题
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