2

I am trying to install a Selenium as a service using NSSM and powershell. But whilst the service is created is does not have the correct parameters set.

The same command run in CMD executes successfully and installs the service as expected.

How do you pass the settings into NSSM with Powershell? The command I am using is:

nssm install SeleniumHub java -jar C:\bin\Selenium2\selenium-server-standalone-2.53.0.jar -role hub -hubConfig C:\bin\Selenium2\seleniumHubConfig.json

NSSM is on my PATH so powershell is correctly finding the NSSM executable but it doesn't seem to handle the parameters in the same way as a CMD

Chris
  • 181
  • 2
  • 9

2 Answers2

2

If it works in CMD why not pass it as a cmd command :)

cmd /c "nssm install SeleniumHub java -jar C:\bin\Selenium2\selenium-server-standalone-2.53.0.jar -role hub -hubConfig C:\bin\Selenium2\seleniumHubConfig.json"
Dewi Jones
  • 785
  • 1
  • 6
  • 18
1

You are correct -- PowerShell does not handle parameters the same was as CMD. The problem here is that some of the NSSM parameters (such as -role and -hub) look like PowerShell parameters, so PowerShell is trying to interpret them, instead of passing them to NSSM.

Enclosing those parameters in quotes will help, but I have found the best way to call a command with parameters is to bundle them up as an array, and use the call operator &.

$params = @('install', 'SeleniumHub', 'java', '-jar',
            'C:\bin\Selenium2\selenium-server-standalone-2.53.0.jar',
            '-role', 'hub', '-hubConfig',
            'C:\bin\Selenium2\seleniumHubConfig.json')
& nssm $params
JamesQMurphy
  • 4,214
  • 1
  • 36
  • 41