This example modifies the Windows's PATH environment and executes specified program.
This can make it easy that a program runs in the isolated environment.
Get the file from Git.
> git clone https://github.com/rubyu/path-override.git
> cd path-override
Here we will try to make an Anaconda environment named IsolatedEnv
, for example.
> conda create -n IsolatedEnv python=2.7
Let's try to activate it.
> call %userprofile%\Anaconda3\Scripts\activate.bat %userprofile%\Anaconda3\envs\IsolatedEnv
If it goes well, let's save the PATH in a file so as not to forget it.
> ECHO %PATH% > path.txt
There is nothing to do in this environment anymore. Let's deactivate.
> deactivate
and, then call the executable file in IsolatedEnv
.
Please note that python.exe
exists below the folder %userprofile%\Anaconda3\envs\IsolatedEnv
.
> path-override.py path.txt %userprofile%\Anaconda3\envs\IsolatedEnv\python.exe --version
The result is the following.
exec_file: C:\Users\user\Anaconda3\envs\IsolatedEnv\python.exe
path_file: path.txt
args: ['--version']
return_code: 0
Python 2.7.14 :: Anaconda, Inc.
Microsoft seems to have a unique view on calling process, especially about arguments. Regarding the escaping of arguments, it is a special one unparalleled. Let's not approach them unless necessary.