I am writing JB IDE plugin (idea, webstorm etc) Inside of the plugin I am using ProcessBuilder to invoke npx command
val builder = ProcessBuilder("npx jest /src/some.test.js").directory(workingDir)
When I execute the command I have this output
Cannot run program "npx" (in directory ...): error=2, No such file or directory
Even if I update the command to somethis like
/path/to/npx jest /src/some.test.js
I will have the same issue but refering node itself
env: node: No such file or directory
So basically I have some issue with PATH env variable like something is missing. So I started logging it.
thisLogger().info("ENV: [\n${builder.environment()}\n]")
And indeed the PATH looks poor and deficient. Way smaller then what I see calling echo $PATH
from the terminal.
I have no issues invoking the same command from the IDE terminal. What can I do to fully inherit the PATH variable in my plugin with ProcessBuilder?
I tried doing something like this
builder.environment()["PATH"] = EnvironmentUtil.getEnvironmentMap()["PATH"]
And repeated the same action for JAVA_HOME, M2_HOME, MAVEN_HOME but it did not work
UPD: Once the same code started to actually work after I rebooted my laptop but after another reboot it stopped working. And now it also does not work for some other people as well.
I started to use GeneralCommandLine instead of ProcessBuilder using some workaround For win
val commandLine = GeneralCommandLine("cmd")
commandLine.addParameters("/c", *restOfTheCommand)
For others
//consider command is Array<String>
val commandLine = GeneralCommandLine(command[0])
commandLine.addParameters(command.drop(1))