Reputation: 302
I have a .bat file with the following two commands:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\..\IDE\devenv" plugin\proj1-vs15.sln /rebuild "Release" /project plugin\proj1-vs15.vcxproj /projectconfig "Release|x64" 1>vcbuild.log 2>&1
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\..\IDE\devenv" plugin\proj2-vs15.sln /rebuild "Release" /project plugin\proj2-vs15.vcxproj /projectconfig "Release|x64" 1>vcbuild.log 2>&1
The first command completes successfully but the second one immediately fails with the message "The process cannot access the file because it is being used by another process."
If I use a different filename for the redirected output in the second command then both commands complete without error.
I haven't had this problem with Visual Studio 2015 or any earlier versions, only with VS 2017.
Why is the redirected output file remaining open after the first devenv command has completed?
In my actual use-case having each execution of devenv.exe use a different filename for the redirected output would be inconvenient. Is there some way of ensuring that the output file is closed before the .bat file advances to the next command?
Upvotes: 0
Views: 277
Reputation: 1463
Any child process that devenv
spawns inherits the redirection handle, So if after debenv returns any of its child process is still open the file remains locked so CMD can not open vcbuild.log
file the second time. The solution is to put both build commands in a redirected compound block.
(
devenv <First Project Arguments>
devenv <Second Project Arguments>
)>"vcbuild.log" 2>&1
Upvotes: 1