How to use vcvarsall.bat in Python for NMake
Question: I'm trying to make a python script to make some generation of MakeFile with
CMake. I'm newbie in Python and just know the basic.

My script runs well but I can't use following command `"cmake
-DCMAKE_BUILD_TYPE=Debug -G"NMake Makefiles" ..\\..\\graphics"` because it
says :

> cmake must be run from a shell that can use the compiler cl from the command
> line.

I know the issue and normally I use call (`C:\Program Files (x86)\Microsoft
Visual Studio 12.0\VC\vcvarsall.bat`) and that's working. How I can reproduce
that in Python ?

Here is my script.py :

    
    
    from os import *
    from subprocess import *
    
    path = "C:\\Users\\mea\\Documents\\repos\\corealpi\\cmake\\graphics_nmake"
    chdir(path)
    info = getcwd()
    print(info)
    call("C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\vcvarsall.bat")
    system('cmake -DCMAKE_BUILD_TYPE=Debug -G"NMake Makefiles" ..\\..\\graphics')
    system("pause")
    path = "C:\\Users\\mea\\Documents\\repos\\corealpi\\cmake\\graphics_nmake"
    chdir(path)
    print (getcwd())
    system('ls')
    

I have had some command path to verify I'm under the good directory.

Thanks for help.


Answer: You have a few options;

  * You can change your system path to include the path exposed by `vcvars.bat`
  * You can edit your shell's path initialization and add the paths you need

I usually do the first one so that I can also use the commands from a regular
windows CMD shell.

