1

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?

4

2 回答 2

7

它在文档中:

var cp = require('child_process');
cp.exec('foocommand', { cwd: 'path/to/dir/' }, callback);
于 2012-12-25T07:49:52.900 回答
0

不是一个完全的专家,但如果它是一个 cli,那么你希望能够使用 stdin 女巫在 process.exec 中不可用。也许你想看看是否有 cli 的可编程接口?

于 2012-12-25T17:09:44.213 回答