Arcengine license issues when calling arcobjects executables from arcpy

09-09-2013 03:00 PM
New Contributor
Arcobjects executable:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using ESRI.ArcGIS;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;

namespace PrintConsole
    class Program
        static int Main(string[] args)
            LicenseInitializer m_AOLicenseInitializer = new PrintConsole.LicenseInitializer();

            //ESRI License Initializer generated code.
            if (!m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine },
            new esriLicenseExtensionCode[] { }))
                System.Console.WriteLine("Print could not initialize with the correct ArcGIS license and will shutdown.");
                return 1;
                Console.WriteLine("made it");
            catch (Exception ex)
                return 1;

            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()

            return 0;

Arcpy script:
import sys, os, arcengine, arcpy, arcpy.mapping, subprocess

mainFolder = os.getcwd().replace("\Bin", "")
arcpy.env.workspace = mainFolder

subprocess.check_call([os.path.join(mainFolder, "Bin", "test.exe")])

The executable works fine by itself, and the arcpy script works fine by itself (assuming I don't try to call the executable). However, it returns the following error when running the arcpy script:

Product: ArcGIS Engine: Not Licensed
Print could not initialize with the correct ArcGIS license and will shutdown.
Traceback (most recent call last):
  File "", line 6, in <module>
    subprocess.check_call([os.path.join(mainFolder, "Bin", "test.exe")])
  File "C:\Python27\ArcGISx6410.2\lib\", line 511, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['D:\\TFS\\test\\Bin\
\test.exe']' returned non-zero exit status 1

Is there something special I need to do with regards to licensing? Is this a bug? Is it possible to use the same ArcEngine license more than once on a single machine?
0 Kudos
0 Replies