eddof13

Arcengine license issues when calling arcobjects executables from arcpy

Discussion created by eddof13 on Sep 9, 2013
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
    {    
        [STAThread()]
        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(m_AOLicenseInitializer.LicenseMessage());
                System.Console.WriteLine("Print could not initialize with the correct ArcGIS license and will shutdown.");
                m_AOLicenseInitializer.ShutdownApplication();
                return 1;
            }
            try
            {
                Console.WriteLine("made it");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return 1;
            }

            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.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:

D:\TFS\test\Bin>python test.py
Product: ArcGIS Engine: Not Licensed
Print could not initialize with the correct ArcGIS license and will shutdown.
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    subprocess.check_call([os.path.join(mainFolder, "Bin", "test.exe")])
  File "C:\Python27\ArcGISx6410.2\lib\subprocess.py", 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?

Outcomes