child-shell: node-powershell was unable to start powershell

I’m adding a feature to Atom Beautify to support formatting PowerShell files/text using PowerShell Beautifier. I came across this package to be able to run the PowerShell module needed for this to happen, however I’m running into this error: Opss... node-powershell was unable to start PowerShell. Please make sure that PowerShell is installed properly on your system, and try again., and a separate message: 'powershell' could not be spawned. Is it installed and on your path? If so please open an issue on the package spawning the process. I’m on a Mac and have installed PowerShell via Homebrew. Atom-Beautify is currently written in CoffeeScript, so the syntax is a little different but here is my code. The relevant part is in the beautify function where it errors out on ps = new shell(). It’s all WIP (and just started)

"use strict"
Beautifier = require('./beautifier')
shell = require('node-powershell')

module.exports = class PowerShellBeautifier extends Beautifier
  name: "powershell-beautifier"
  link: "https://github.com/DTW-DanWard/PowerShell-Beautifier"

  options: {
    PowerShell: false
  }

  beautify: (text, language, options) ->
    ps = new shell()
    tempFile = @tempFile("input", text)
    ps.addCommand("Set-PSRepository -Name PSGallery -InstallationPolicy Trusted")
    ps.addCommand("Install-Module -Name PowerShell-Beautifier")
    ps.addCommand("Edit-DTWBeautifyScript " + tempFile)
    ps.invoke().then(=> @readFile(tempFile)).catch(err => {})

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (1 by maintainers)

Commits related to this issue

Most upvoted comments

@rannn505 Please can you merge this PR, cause everything works great except that.

Thanks 😃

don’t forget you need to pass a parameter to use PowerShell Core “pwsh”

shell = require('node-powershell')
ps = new shell(usePwsh: true)

Can you try my fork and then report back to us if it meets your needs?

https://github.com/BenjaminMichael/node-powershell