<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic arcpy.CreateMobileCache_mobile forcing system's %errorlevel% variable to -2146234327 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-createmobilecache-mobile-forcing-system-s/m-p/193031#M14825</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have created a python script that has the purpose of automating the generation of mobile caches which utilizes the &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//003z00000005000000" rel="nofollow noopener noreferrer" target="_blank"&gt;CreateMobileCache_mobile&lt;/A&gt; function. This python script is required to run from within a batch script which checks the value of %errorlevel% to see whether an error has occurred in the python script (0 = no error, 1 = error). I have found that no matter what I try, the call to the CreateMobileCache_mobile function produces an errorlevel of -2146234327, whether the call itself fails or succeeds, and overrides my own sys.exit call that should be returning a 0 or 1, depending. I should mention, I've tested this on ArcGIS 10.1, 10.2, 10.2.1. Has anyone run into this issue and know a way to 'catch' this or prevent it? I've tried to surround the call with a try/except, but nothing is caught by the except.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a code example of the isolated issue:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;startGenerateCache.bat&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;REM will return error level of 0 since nothing has been done yet
echo %errorlevel%

REM run the python script
C:\Python27\ArcGIS10.2\python.exe generateCache.py

REM will always return the large error level of -2146234327
echo %errorlevel%&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;generateCache.py&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

# Set some variables up as example map document and output folder location
theMXD = "C:\anMXD.mxd"
theOutputFolder = "C:\output"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Call the Create Mobile Cache tool from arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateMobileCache(theMXD, theOutputFolder, "", "", "")
except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Print out any error messages (this never gets triggered...)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(arcpy.GetMessages(2))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:41:23 GMT</pubDate>
    <dc:creator>DominickAlfonso</dc:creator>
    <dc:date>2021-12-11T09:41:23Z</dc:date>
    <item>
      <title>arcpy.CreateMobileCache_mobile forcing system's %errorlevel% variable to -2146234327</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-createmobilecache-mobile-forcing-system-s/m-p/193031#M14825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have created a python script that has the purpose of automating the generation of mobile caches which utilizes the &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//003z00000005000000" rel="nofollow noopener noreferrer" target="_blank"&gt;CreateMobileCache_mobile&lt;/A&gt; function. This python script is required to run from within a batch script which checks the value of %errorlevel% to see whether an error has occurred in the python script (0 = no error, 1 = error). I have found that no matter what I try, the call to the CreateMobileCache_mobile function produces an errorlevel of -2146234327, whether the call itself fails or succeeds, and overrides my own sys.exit call that should be returning a 0 or 1, depending. I should mention, I've tested this on ArcGIS 10.1, 10.2, 10.2.1. Has anyone run into this issue and know a way to 'catch' this or prevent it? I've tried to surround the call with a try/except, but nothing is caught by the except.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a code example of the isolated issue:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;startGenerateCache.bat&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;REM will return error level of 0 since nothing has been done yet
echo %errorlevel%

REM run the python script
C:\Python27\ArcGIS10.2\python.exe generateCache.py

REM will always return the large error level of -2146234327
echo %errorlevel%&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;generateCache.py&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

# Set some variables up as example map document and output folder location
theMXD = "C:\anMXD.mxd"
theOutputFolder = "C:\output"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Call the Create Mobile Cache tool from arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateMobileCache(theMXD, theOutputFolder, "", "", "")
except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Print out any error messages (this never gets triggered...)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(arcpy.GetMessages(2))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:41:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-createmobilecache-mobile-forcing-system-s/m-p/193031#M14825</guid>
      <dc:creator>DominickAlfonso</dc:creator>
      <dc:date>2021-12-11T09:41:23Z</dc:date>
    </item>
  </channel>
</rss>

