I want to run bash script with params in node js child_process.exec()
In doc is String The command to run, with space-separated arguments
, but
child.exec("cat path_to_file1 path_to_file2")
doesn't work. It is internally changed to
/bin/sh -c cat path_to_file1 path_to_file2
which fails. How can I run this correctly? In shell I would fix it this way
/bin/sh -c 'cat path_to_file1 path_to_file2'
(I didn't write callbacks, because I ask only about command param)
Use the shell option of exec :
child.exec("cat path_to_file1 path_to_file2", {
shell : '/bin/bash'
})
see options : https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With