2

The code given below is an excerpt from vcvarsall.bat file used to set the environment variables for Visual C++ Command Line. Due to the errors(mentioned in the code as REM statements), the environment variables are not set.

:x86

if exist "%~dp0bin" echo "%~dp0bin exists" 

REM The above line gives "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin exists" as output.

if not exist "%~dp0bin\vcvars32.bat" goto missing

call "%~dp0bin\vcvars32.bat"

REM The above line gives 'C:\Program' is not recognized as an internal or external command as output.
goto :SetVisualStudioVersion

Since the environment variables are not set I ran into runtime errors while building an nmake project.

I have gone through this SO question and this post but the workarounds didn't help.

Could anyone suggest a workaround for calling the call with spaces and parentheses in the path?

Edit:

I have placed a test echo statement in the beginning of the vcvars32.bat file which is being called. Had the file been run this statement should have been executed with the statement printed on the screen. Moreover I am sure that the program flow is through the block labelled :x86 because the test echo statements which are put there are run.

Edit 2 : After following the suggestions from Paul & Co, changed the normal set command to extended syntax that is with the quotes. On running the vcvars32.bat the execution stops at the below lines :

@if not "%WindowsSDK_ExecutablePath_x86%" == "" (
    @set "PATH=%WindowsSDK_ExecutablePath_x86%;%PATH%"
)

The error shown is:

\Microsoft was unexpected at this time.
Community
  • 1
  • 1
sjsam
  • 21,411
  • 5
  • 55
  • 102
  • Actually I don't see any error here, your code looks fine, as there are quotes around the paths containing spaces and `()`; so are you absolutely sure that the error is thrown by the line you suspect? – aschipfl Oct 14 '15 at 05:48
  • 2
    It seems that your problem is not the call to `vcvars32.bat`, but the code inside the called file. – MC ND Oct 14 '15 at 05:50
  • @MCND : Thanks for that tip, Let me check that – sjsam Oct 14 '15 at 05:51
  • @aschipfl : Please see the edit.. – sjsam Oct 14 '15 at 06:20
  • @MCND hit the spot, I guess... so run `vcvars32.bat` directly from command line and tell us what happens... – aschipfl Oct 14 '15 at 07:00
  • 1
    The main problem here, was the fact that some variables contain quotes(I got the info in the chat). Then the extended SET syntax can't solve it alone. – jeb Oct 14 '15 at 13:58

2 Answers2

1

After the help from @Jeb, I am able to resolve this error using the below tweak in vcvars32.bat.

I added

@set PATHTEMP=%PATH%
@set PATH=%PATHTEMP:"=%

before

@if not "%WindowsSDK_ExecutablePath_x86%" == "" (
    @set "PATH=%WindowsSDK_ExecutablePath_x86%;%PATH%"
)

Basically I just stripped the quotes from the PATH variable.

(Indebted to @jeb for his valuable suggestion).

sjsam
  • 21,411
  • 5
  • 55
  • 102
0
:x86
if exist "%~dp0bin\nul" (
    rem this IF statement is useless since you are going to check if vcvars32.bat exist 
    echo "%~dp0bin exists" 
)

set "_MVS=%ProgramFiles(x86)%\Microsoft Visual Studio 12.0\VC\bin"
if not exist "%_MVS%\vcvars32.bat" (
    echo "%_MVS%\vcvars32.bat" is missing
    echo please fix it and retry again.
    exit /b 0
)
call "%~dp0bin\vcvars32.bat"

I added \nul in if exist "%~dp0bin\nul" to differentiate between file and folder.

Paul
  • 2,620
  • 2
  • 17
  • 27
  • :Thankyou , but. I have already tried the extended syntax of set – sjsam Oct 14 '15 at 05:24
  • The label missing is actually present in the code, not included here for the sake of brevity. – sjsam Oct 14 '15 at 05:28
  • I guess the label is not the issue here. The lable `:missing` is actually present at the end of this shipped file The line `call "%~dp0bin\vcvars32.bat"` is the one that throws the error `The above line gives 'C:\Program' is not recognized`. I already tried your workaraound. Is there any way to fix the call statement? – sjsam Oct 14 '15 at 05:35
  • @sjsam I know the label is not the problem, But I remove it for the sake of brevity :) . Be sure all your variables are correctly double quoted like for `_MVS` example `set "myvar=something with space"` – Paul Oct 14 '15 at 05:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92215/discussion-between-sjsam-and-paul). – sjsam Oct 14 '15 at 05:42
  • I have send you the whole script in the chat – sjsam Oct 14 '15 at 05:49