'Batch File SUBST command but only remap for current process
I have a jenkins job that executes a batch file. Due to some path length issues, I need to remap the jenkins working directory to a drive name using the SUBST command. The batch file looks something like this:
@echo off
REM Map working directory to a virtual drive P:
subst P: .
REM Save the original working directory so we can pop back out after we're done
pushd .
cd P:
REM *DO STUFF*
REM Pop out of P: and back to original working directory
popd
REM Unmount P: so it can be reused for future jenkins jobs
subst P: /D
I need to unmount because SUBST changes are global for a given user. The problem is what if the jenkins job is inside the "DO STUFF" and someone cancels the job? Then the job wouldn't have a chance to execute "subst P: /D" and therefore P: will never be unmounted. And batch doesn't support any kind of sigtrap. Is there another batch command that does what SUBST does but local to the calling shell?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
