8
我试图在Windows上获取Node.js中文件的所有者。在没有WIN32API的,我想我会使用PowerShell命令:从NodeJS调用PowerShell
powershell -Command "(get-acl test.txt).owner"
这种由命令行和批处理文件作品完美,但只是Node.js的exec()
挂起:
var exec = require('child_process').exec;
exec('powershell -Command "(get-acl test.txt).owner"', function(err,sysout,syserr) {
console.dir(sysout);
});
PowerShell进程看起来开始并且从不终止。
有谁知道:
- 为什么该命令将不会在返回的Node.js,最好
- 一个健全的办法,我在Windows上获取文件所有者与Node.js的一个想法?
我用'child = exec(...); child.stdin.end();'它完美地工作。谢谢。 – tjdett 2012-02-06 08:19:35
这个答案也适用于我。谢谢。一个注释可供其他人参考,或对此有所怀疑。这只发生在没有stdin.end()调用的Powershell 2和更早的版本(2个Windows 7附带)上。对于Powershell 3和更高版本(3个Windows 8和5与10),这是没有必要的,并按预期工作。 – 2016-01-01 21:54:52