-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getting powershell output back into javascript #147
Comments
Hi, I have been doing this for an automation project let output = await shell.invoke(`Get-VM -Server ${server.ip} | Select-Object -Property Name,Uid,PowerState | ConvertTo-Json -Compress -Depth 99`); The output includes some whitespace and stuff, so I remove that console.log(JSON.parse(output.raw.replace("\u001b[?1h\u001b[?1l", "").replace("�[?1h�[?1l�[?1h�[?1l", ""))); And thats it. Seems a bit fragile though, but I run everything in a docker container so hopefully won't have to worry. |
New update on this. It seems that different commands produce different junk around the command. It seems deterministic, but very annoying. I do not get those warnings when running the same command in my normal powershell window, so not sure where they come from. Command: Output when running through child-shell:
I solved it by adding |
You are seeing that "junk" output because all your PS logs are getting clumped into one output. Do something like this and you will get a clean JSON output |
Here's an example I'm using with node-powershell version 5.0.1
Alternatively if you want to use async/await this is another example
|
Thanks for the neat code.
If no other way, I think that I'll need to new it and psOut.invoke(somecmd)... |
How can I get Powershell's output back into javascript as a object or array? My code is below. I'd like to be able to display the output of the command via html page.
The text was updated successfully, but these errors were encountered: