Can't call CMake from a Python script
<p>I'm trying to call the <a href="http://en.wikipedia.org/wiki/CMake" rel="nofollow">CMake</a> command from a Python script. This is my code:</p>

<pre><code>cmakeCmd = ["C:\Program Files\CMake\bin\cmake.exe",'-G Visual Studio 11 Win64', 'C:\Users\MyUser\Desktop\new\myProject']
retCode = subprocess.check_call(cmakeCmd, shell=True)
</code></pre>

<p>But I get the following output when running the script:</p>

<pre><code>The filename, directory name, or volume label syntax is incorrect.
Traceback (most recent call last):
  File "C:\Users\ochitaya\Desktop\New\myProj\sc.py", line 10, in &lt;module&gt;
    retCode = subprocess.check_call(cmakeCmd, stderr=subprocess.STDOUT, shell=True)
  File "C:\Python27\lib\subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\\Program Files\\CMake\x08in\\cmake.exe', '-G Visual Studio 11 Win64', 'C:\\Users\\ochitaya\\Desktop\new\\myProj']' returned non-zero exit status 1
</code></pre>

<p>A backslash (<code>\</code>) in a Python string is an escape character. That's why the string <code>"C:\Program Files\CMake\bin\cmake.exe"</code> is translated to <code>C:\\Program Files\\CMake\x08in\\cmake.exe</code> (notice that <code>\b</code> equals <code>\x08</code>). To fix this, tell Python you want the string to be read as-is, or in other words, as a <strong>raw</strong> string, by prefixing the string with <code>r</code>:</p>

<pre><code>cmakeCmd = [r"C:\Program Files\CMake\bin\cmake.exe",'-G Visual Studio 11 Win64', r'C:\Users\MyUser\Desktop\new\myProject']
</code></pre>

<p>For more on this topic, take a look at the official documentation on <a href="https://docs.python.org/2/reference/lexical_analysis.html#string-literals" rel="nofollow">string literals</a>.</p>

python cmake