How to run node js script from powershell script and use the output of node js script in powershell script?

I have a node js script that can return a string value. I want to return that value and use it in PowerShell script.

I have done console.log(); to print the output. How to use it in PowerShell script?
The output looks like this:

D:developmentjs-automation>node index.js MyNewProject
MyNewProject
https://github.com/avadhvashisth/MyNewProject.git

Answer

Powershell can capture all the standard output to a string. Make sure you specify the path to your node.exe and include the file extension or Powershell will consider it a command:

$MyOutput = .node.exe index.js MyNewProject

$MyOutput should contain everything returned by node

Leave a Reply

Your email address will not be published. Required fields are marked *