ConfusedNoob
ConfusedNoob

Reputation: 10186

calling child_process.exec in Node as though it was executed in a specific folder

I'm using the following to execute a CLI command in nodeJS

var cp = require('child_process');
cp.exec('foocommand', callback);

However, the foocommand is executing in the current folder node is running from. How can I make it execute as though it is being invoked from a different folder?

Upvotes: 2

Views: 2561

Answers (2)

Ari Porad
Ari Porad

Reputation: 2922

Not a total expert but if its a cli then you want to be able to use stdin witch is not available with process.exec. Maybe you want to see if there is a programable interface for the cli?

Upvotes: 0

Andrey Sidorov
Andrey Sidorov

Reputation: 25456

Its in the docs:

var cp = require('child_process');
cp.exec('foocommand', { cwd: 'path/to/dir/' }, callback);

Upvotes: 8

Related Questions