[cmake-developers] execute_process inconsitancy

Brad King brad.king at kitware.com
Tue Sep 4 08:24:23 EDT 2012


On Tue, Sep 4, 2012 at 2:19 AM, J Decker <d3ck0r at gmail.com> wrote:
> On Mon, Sep 3, 2012 at 7:50 PM, David Cole <david.cole at kitware.com> wrote:
>> That's not a workaround, that's the solution. The quotes don't belong there.
>
> I dunno seems to be an application specific failure....

Python:

 c:\>set PATH=c:\Python;C:\Windows\system32;C:\Windows
 c:\>python -c "import subprocess; subprocess.call(['hg','--version'])"
 WindowsError: [Error 2] The system cannot find the file specified

 c:\>set PATH="C:\Program Files\Mercurial";c:\Python;C:\Windows\system32;C:\Windows
 c:\>python -c "import subprocess; subprocess.call(['hg','--version'])"
 WindowsError: [Error 2] The system cannot find the file specified

 c:\>set PATH=C:\Program Files\Mercurial;c:\Python;C:\Windows\system32;C:\Windows
 c:\>python -c "import subprocess; subprocess.call(['hg','--version'])"
 Mercurial Distributed SCM (version 2.1)

CMake:

 c:\>type test.cmake
 execute_process(COMMAND hg --version RESULT_VARIABLE failure)
 if(failure)
   message(STATUS "failed to run hg: ${failure}")
 endif()

 c:\>set PATH=c:\Program Files (x86)\CMake 2.8\bin;C:\Windows\system32;C:\Windows
 c:\>cmake -P test.cmake
 -- failed to run hg: The system cannot find the file specified

 c:\>set PATH="C:\Program Files\Mercurial";c:\Program Files (x86)\CMake 2.8\bin;C:\Windows\system32;C:\Windows
 c:\>cmake -P test.cmake
 -- failed to run hg: The system cannot find the file specified

 c:\>set PATH=C:\Program Files\Mercurial;c:\Program Files (x86)\CMake 2.8\bin;C:\Windows\system32;C:\Windows
 c:\>cmake -P test.cmake
 Mercurial Distributed SCM (version 2.1)

If you use execute_process's RESULT_VARIABLE you can get the
real result of the process instead of just assuming success.
It will either be an integer return code or a message indicating
a problem launching the process.

-Brad



More information about the cmake-developers mailing list