NodeJ的child_process工作目录 [英] NodeJs child_process working directory
本文介绍了NodeJ的child_process工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行子进程在与以下目录不同的目录中它的父母。
I am trying to execute a child process in a different directory then the one of its parent.
var exec = require('child_process').exec;
exec(
'pwd',
{
cdw: someDirectoryVariable
},
function(error, stdout, stderr) {
// ...
}
);
我正在执行上述操作(尽管运行 pwd当然不是我想要做的到底)。不管我为cdw选项提供什么值,最终都会将父进程的pwd写入stdout。
I'm doing the above (though of course running "pwd" is not what I want to do in the end). This will end up writing the pwd of the parent process to stdout, regardless of what value I provided to the cdw option.
我缺少什么?
(我确实确保通过cwd选项传递的路径确实存在)
(I did make sure the path passed as cwd option actually exists)
推荐答案
当前工作目录的缩写,缩写为 cwd
,而不是 cdw
。
The option is short for current working directory, and is spelled cwd
, not cdw
.
var exec = require('child_process').exec;
exec('pwd', {
cwd: '/home/user/directory'
}, function(error, stdout, stderr) {
// work with result
});
这篇关于NodeJ的child_process工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文