Start windows batch from C++ CreateProcess has different behavior

607 views Asked by At

Environment: windows 10, VS2013.

I have a C++ app, using Poco framework (Poco 1.7.6) and I need to launch some batch files. It works without problem, but for a particular script, and I can't figure out the reason. This particular script is as follows (let's call it buildMySolution.bat):

set BUILD_DIR=%~dp0
call "C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
msbuild /p:Platform=%~1 /p:Configuration=%~2  %BUILD_DIR%\Mysolution.sln

As you can see the batch file simply compiles a VS2013 solution. Needless to say that this simple batch works perfectly well if launched from command line.

The problem is that this batch is in drive D: (in D:\DevRoot\build\MySolution) and when launched from my app (in D:\ drive as well), I get a "cannot find the path" on the second line.

I tried several modifications in the batch: like forcing C: or cd /D C: ... it can go to C: but not further, it refuses to cd to the directory containing vcvarsall.bat (again, I know the path is correct as the very same script executes fine from command line). It has however no problem coming back to initial directory through a cd /D %BUILD_DIR%.

To launch the script from my C++ app, I use this:

Poco::ProcessHandle handleBuild = Poco::Process::launch(path_to_script, argsBuild);
handleBuild.wait();

The Poco launch is just a thin wrapper around CreateProcessA(), I don't see anything special in their code (Poco Process.cpp).

I tried as well to specify the working directory to be the directory containing vcvarsall.bat, but then CreateProcess fails.

1

There are 1 answers

7
SoyonsPrecis On BEST ANSWER

I just found a solution: I changed the line (in the batch buildMySolution.bat):

call "C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"

to:

call C:\PROGRA~2\micros~1.0\vc\vcvarsall.bat

Believe it or not: using DOS names and removing quotes makes it work!!!

Bug or feature, I'm not sure...