# Running ArcPy script from ArcObjects?

the standard method requires to run ArcPy script in command line, i've struggled with it to run but without a result, i can import arcpy, set the workspace to the geodatabase path and describe the env variable using arcpy.Describe(arcpy.env.workspace).name it gives me the geodatabase name, but when i try to get featureclasses using arcpy.ListFeatureClasses() i get [], i have made sure that all the environement variables in PATH and PYTHONPATH are ok .

i would like to know if there's an alternative way to run ArcPy script, like it could be run in ArcMap console, is there a way to send scripts to ArcMap console using ArcObjects, what's the difference between ArcMap console and standard command line console?

so any way to run an ArcPy script using ArcObjects 10 or Arcgis Engine 10 will be very welcome.

-
I suggest you get the Python script working by itself first before trying to call it from another environment. –  blah238 Jun 26 '12 at 3:10
i've tested Arcpy script in Arcmap console, it works like expected in arcmap, but in commande line console, it do not work –  geogeek Jun 26 '12 at 7:37

There may be several options. If you package your script into a toolbox you could reference your toolbox (and tool) via ArcObjects as such:

 IGeoProcessor2 gp = new GeoProcessorClass();
gp.Execute("NameOfYourToolInsideReferencedToolbox", parameters, null);


Read more on this method here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#executingCustomTool

Or you could try this route:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = @"C:\path\toYour\script.py";
proc.StartInfo.UseShellExecute = true;
proc.Start()


thanks i've made an edit, but in despite of using arcpy.ListFeatureClasses() i get an empty array, but in ArcMap console i get all the featureclasses [u'new_dir_sj', u'new_dir6', u'dir_buf', u'div_riv'] –  geogeek Jun 26 '12 at 6:06