Change process PATH dynamically inside a package


#1

Hello everyone,

I am trying to change the current PATH dynamically after the editor is opened. My idea is to add a new directory to the path. This directory will contain some .exe files.

My code:

process.env.PATH = process.env.PATH + ";" + "C:\\MyNewPathWithExes\\"

After changing the path, I am trying to execute some of these .exe files but Atom says that these .exe files don`t exist. Is it possible to change the PATH dynamically in Windows?

P.S: I am having success adding new scripts to the path using Linux. My problem is only with windows.

Thanks,


#2

How exactly are you trying to execute the files?

It’s possible that you’re changing the PATH for the main process, but it’s a child process that has already started that is trying to start the executable. Right now, I have one Atom window open, but there are five processes running.


#3

I am trying to create a plug-in to change the virtualenv (https://virtualenv.pypa.io/en/stable/) dynamically inside atom, so I need to change the PATH of the current process. To change the path I am getting the process and adding the paths that are inside the virtualenv into the process path:

process.env.PATH = process.env.PATH + ";" + myVirtualEnvPaths

This idea works on Linux but does not work on Windows. :frowning:


#4

Can you verify that after you set process.env.PATH in the current process that it is actually changed? Can you verify what process.env.PATH is set to in the sub-process? Also, can you verify the behavior you’re seeing with all community packages besides your own disabled? It could be that some other package you have installed is reversing your change (why it would do that only on Windows, I’m not sure … but I’m just spitballing here :grinning:)