test.bat
@echo off
for /f "delims=" %%i in ('winrs /r:REMOTE_MACHINE /u:DIFF_USER_ACCOUNT /p:PASS /noprofile "echo %PYTHONPATH%"') do set dest_dir=%%i
echo %dest_dir%
This script is meant to remote into the REMOTE_MACHINE
and print out the contents of the PYTHONPATH
env var. I intentionally pass the /noprofile
switch since I do not want to access REMOTE_MACHINE
with my account (which also exists on the box), which is the default behavior of winrs
.
What ends up happening is that the script executes and remotes into the REMOTE_MACHINE
using my user account, and not the DIFF_USER_ACCOUNT
that was specified. The way I determine this is because the PYTHONPATH
is different between the two accounts.
I've also created a new env variable that only exists on DIFF_USER_ACCOUNT
and the batch script cannot access it.
Running the same command 'winrs /r:REMOTE_MACHINE /u:DIFF_USER_ACCOUNT /p:PASS /noprofile "echo %PYTHONPATH%"'
in the shell, or just in the script without the subshell, provides the correct behavior.
Why does this happen, and how do I fix this?