Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs ignoring cwd while spawning a child process

Tags:

node.js

I am trying to spawn a child process with a default directory. The process is being executed and it is able to read the args. But the process starts up in the current directory, even though I am providing cwd as options. Am I doing this incorrectly?

var spawn = require('child_process').spawn;
var child = spawn("sh",
   ["path_to_file_name", "args"],
   [{cwd:"/some/path/temp"}]
);

My end goal is to execute a bash script, in a specific folder so that it doesn't mess up my application directory.

Node version : 4.0.0

like image 250
Rahul Soni Avatar asked Oct 28 '25 05:10

Rahul Soni


1 Answers

options is an object, not array.

var child = spawn("sh",
   ["path_to_file_name", "args"],
   {cwd:"/some/path/temp"}
);
like image 127
vinayr Avatar answered Oct 30 '25 23:10

vinayr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!