<div dir="ltr">Hi David, <br><br><div><div><div>You need to escape the &quot;$&quot; sign otherwise the &quot;_err&quot;, &quot;_out&quot; and &quot;_res&quot; variables are resolved to an empty string.<br><br></div>Here is an example of what you could do:<br>


<br>-------------8&lt;-----------8&lt;----------<br>cmake_minimum_required(VERSION 2.8.9)<br><br>install(CODE &quot;execute_process (<br>      COMMAND ${CMAKE_COMMAND} -E echo \&quot;Hello\&quot;<br>      OUTPUT_VARIABLE _out<br>


      ERROR_VARIABLE _err<br>      RESULT_VARIABLE _res<br>      )&quot; <br>   )<br>install(CODE &quot;message( STATUS \&quot;out: \${_out}, err: \${_err}, res: \${_res}...\&quot;)&quot;)<br>-------------8&lt;-----------8&lt;----------<br>


<br></div>Hth<br></div>Jc<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 13, 2013 at 2:29 PM, David Hauck <span dir="ltr">&lt;<a href="mailto:davidh@netacquire.com" target="_blank">davidh@netacquire.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Kornel,<br>
<div><div><br>
On Wednesday, November 13, 2013 11:08 AM, <a href="mailto:cmake-bounces@cmake.org" target="_blank">cmake-bounces@cmake.org</a> wrote:<br>
&gt; Am Mittwoch, 13. November 2013 um 18:41:03, schrieb David Hauck<br>
&gt; &lt;<a href="mailto:davidh@netacquire.com" target="_blank">davidh@netacquire.com</a>&gt;<br>
&gt;&gt; Hi Kornel,<br>
&gt;&gt;<br>
&gt;&gt; On Wednesday, November 13, 2013 10:26 AM, cmake-<br>
&gt; <a href="mailto:bounces@cmake.org" target="_blank">bounces@cmake.org</a> wrote:<br>
&gt;&gt;&gt; Am Mittwoch, 13. November 2013 um 18:12:26, schrieb David Hauck<br>
&gt;&gt;&gt; &lt;<a href="mailto:davidh@netacquire.com" target="_blank">davidh@netacquire.com</a>&gt;<br>
&gt;&gt;&gt;&gt; Hello,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I&#39;ve been using several &quot;install (CODE &quot;EXECUTE_PROCESS ...&quot;)&quot;<br>
&gt;&gt;&gt;&gt; constructs<br>
&gt;&gt;&gt; in my top-level CMakeLists.txt file. However, I&#39;ve been unable to<br>
&gt;&gt;&gt; capture/operate on any exit status of the embedded command.<br>
&gt;&gt;&gt; Unfortunately, documentation/searches haven&#39;t turned up any useful<br>
&gt;&gt;&gt; pointers. The closest I&#39;ve come is a pointer in the following thread:<br>
&gt;&gt;&gt;&gt; <a href="http://www.cmake.org/pipermail/cmake/2011-July/045475.html" target="_blank">http://www.cmake.org/pipermail/cmake/2011-July/045475.html</a> However,<br>
&gt;&gt;&gt;&gt; I&#39;ve not been able to sufficiently read between the lines to get<br>
&gt;&gt;&gt;&gt; this working.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Does anyone have any thoughts on how to get something like the<br>
&gt;&gt;&gt;&gt; following working:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;    install (CODE &quot;EXECUTE_PROCESS (<br>
&gt;&gt;&gt;&gt;       COMMAND ant ...<br>
&gt;&gt;&gt;&gt;       WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/java<br>
&gt;&gt;&gt;&gt;       ERROR_VARIABLE _err<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Didn&#39;t you mean &#39;RESULT_VARIABLE&#39; here?<br>
&gt;&gt;<br>
&gt;&gt; No, I really do mean ERROR_VARIABLE (unless, of course, this variable<br>
&gt;&gt; does<br>
&gt; not include the non-zero exit status of the EXECUTE_PROCESS command?).<br>
&gt;<br>
&gt; If you run &#39;cmake --help-command execute_process&#39;, you see: ... If<br>
&gt; RESULT_VARIABLE is given the variable will be set to contain the<br>
&gt; result of running the processes.  This will be an integer return code<br>
&gt; from the last child or a string describing an error condition. ... So,<br>
&gt; if this is not &quot;0&quot;, then you have an error condition.<br>
<br>
</div></div>Yes, I see this. I also assumed that the ERROR_VARIABLE would be returning non-zero text as well in this case. I will change to using RESULT_VARIABLE, but, in both cases, it seems that I&#39;m referencing the variable incorrectly (either syntactically or in the incorrect context) since this/these is/are always &lt;empty&gt;.<br>



<div><br>
&gt;&gt; BTW, I&#39;m still curious about the (dual &#39;code&#39;) construct generally.<br>
&gt;&gt; Specifically, if I do the following I never see the fatal error<br>
&gt;&gt; message (so I&#39;m wondering if there&#39;s still something wrong regarding<br>
&gt;&gt; the scoping of the message command)?<br>
&gt;&gt;<br>
&gt;&gt;    install (CODE &quot;EXECUTE_PROCESS (<br>
&gt;&gt;       COMMAND ant ...<br>
&gt;&gt;       WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/java<br>
&gt;&gt;       ERROR_VARIABLE _err<br>
&gt;&gt;    )<br>
&gt;&gt;    MESSAGE( FATAL_ERROR \&quot;err: ${_err}\&quot;)<br>
&gt;<br>
&gt; Never did this. When do you want to see the message?<br>
<br>
</div>Ideally, I want to be able to test for the result of this variable (either ERROR_VARIABLE or RESULT_VARIABLE) after the execute_process command completes (during &#39;make install&#39;) to determine its result and to terminate (with error message) when the command fails.<br>



<br>
Thanks,<br>
-David<br>
<div><br>
&gt; As I understand your code, only in call of cmake, e.g. at configuration time.<br>
&gt;<br>
&gt;       Kornel<br>
</div><div><div>--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="tel:%2B1%20919%20869%208849" value="+19198698849" target="_blank">+1 919 869 8849</a><br>
</div></div>