[英]Calling PowerShell from NodeJS
我試圖在Windows上獲取Node.js中文件的所有者。 在沒有win32api的情況下,我想我會使用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進程似乎剛開始並且永不終止。
有人有:
當您像這樣調用Powershell時,您需要關閉輸入流。 您可能想嘗試使用spawn並使用stdin.end()
。
其他選項是調用cmd /c dir /q <file>
但該輸出是詳細的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.