windowswindows-servicesprocrunapache-commons-daemon

Apache Common Daemons : PrunServ --StartPath parameter overriding PATH on windows


I am running a java program on windows 10 workstation.

I wanted to run my java program as a service so i used apache commons tool prunserv http://commons.apache.org/proper/commons-daemon/procrun.html

Issue is my java program runs some windows shell commands inside it like cmd \c netstat -rn but when i start my java program as a service and specify StartPath as some directory. commands inside my java programs fail with error like below

Error executing command : [cmd, /c, netstat, -rn], Output is : 'netstat' is not recognized as an 
internal or external command,
operable program or batch file.

I feel like StartPath argument of procrun is overriding PATH variables like C:\Windows\System32 thus making command inside java program to fail

--StartPath Working path for the start image executable.

How should i deal with this situation ?

Let me know if you need any further details.

Thanks in advance for help.


Solution

  • Procrun(Prunserv) provides an option for setting Environment

    http://commons.apache.org/proper/commons-daemon/procrun.html

    ++Environment="PATH='C:\Users\Public\agent\jre\bin';'C:\Windows\system32'"
    

    I added C:\Windows\system32 in Environment and it worked fine.

    Note : Environment option in prunserv is List of environment variables that will be provided to the service in the form key=value. They are separated using either # or ; characters. If you need to embed either # or ; character within a value put them inside single quotes.