PowerShell call from NodeJS

I am trying to get the owner of a file in Node.js on Windows. In the absence of win32api, I decided to use the PowerShell command:

powershell -Command "(get-acl test.txt).owner" 

This works fine from the command line and from the batch file, but just hangs with Node.js exec() :

 var exec = require('child_process').exec; exec('powershell -Command "(get-acl test.txt).owner"', function(err,sysout,syserr) { console.dir(sysout); }); 

The PowerShell process just starts and never ends.

Does anyone have:

  • the idea of ​​why the team will not return to Node.js or preferably
  • a sensible way to force a file owner with Node.js on Windows?
+8
javascript windows powershell
source share
1 answer

When you call Powershell, you need to close the input stream. You can try using caviar and use stdin.end() .

Another option is to call cmd /c dir /q <file> , but this output is verbose.

+9
source share

All Articles