Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 623
Dan Ramos Avatar asked Sep 02 '25 09:09

Dan Ramos


2 Answers

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

like image 95
Yousef Avatar answered Sep 03 '25 21:09

Yousef


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

like image 34
Peter Lyons Avatar answered Sep 03 '25 21:09

Peter Lyons