Select to view content in your preferred language

Command Prompt ArcGIS 10.2

1107
6
02-27-2014 04:49 AM
AndrewTuleya1
New Contributor
In the past I have used command prompt to run batch files that consist of Python Commands with ArcGIS tools. From what I understand you are no longer able to do so with 10.2. Has anyone else experienced this or figured out a work around besides the python window?
Tags (2)
0 Kudos
6 Replies
MathewCoyle
Frequent Contributor
What error are you getting? Try reading through this if you are having issues.

http://docs.python.org/2/faq/windows
0 Kudos
AndrewTuleya1
New Contributor
So I just exported a python script (From Model Builder) and put it into an open source text editor called "Jedit". I created a batch file with the following command (cmd/k W:\GIS_Scripts\Test\Example.py) and saved it as Run.bat. When i double click to run the .bat file, the command prompt window open with the location of the python file on the first line and then nothing after. Also when i double click the .bat file, a wordpad document opens and contains all my script's syntax. I an using 10.2, but all of my commands in the script use ArcGIS tools such as copy, append, ect. Before on 9.3 i would run the batch file and it would run fine within the command prompt window. Any ideas why it wont run in 10.2?
0 Kudos
FreddieGibson
Occasional Contributor III
You should be able to execute python commands from Command Prompt with any version of ArcGIS.  If you see that your python scripts are opening with wordpad, the problem may be that you have wordpad set as your default program to open *.py files. I would say that you'd want to try doing one of the following:

1. Add the C:\Python27\ArcGIS10.2 folder to your system's path variable and call the script generated from modelbuilder as such in your batch file.

python "c:\Path\To\Script.py"

2. Use the full path to the python executable in your batch file when calling the scripts.

C:\Python27\ArcGIS10.2\python.exe "c:\Path\To\Script.py"

On a side note, you may want to note that exporting a script from ModelBuilder doesn't guarantee that the model will work.  This workflow should be used to create the "skeleton" for what your code would look like and you should always go through this output and refactor the code before executing it. 

For the most part, a quick test to check if you model is suitable for running outside of ArcMap would be to run it from the ArcCatalog application.  This will ensure that you're not using any in-memory features in your model that are only available to the Map Document.
0 Kudos
AndrewTuleya1
New Contributor
Thanks for the input,

The tools that I am using in Model Builder work fine outside of catalog or a map document. This problem only started to occur when i got a new computer and downloaded 10.2 and am not longer using 9.3.
0 Kudos
AndrewTuleya1
New Contributor
I'm not sure if I am following.

Here is the path of my script
W:\GIS_Scripts\Test\Example.py

Here is the path of my batch file
W:\GIS_Scripts\Test\Run.bat

Here is the line in my batch file to run the command
cmd/k W:\GIS_Scripts\Test\Example.py

I'm not sure what you recommend doing with C:\Python27\ArcGIS10.2\python.exe?
0 Kudos
MattEiben
Occasional Contributor
If you're looking to exectue a Python script on your system, but don't want to mess with or don't have access to your system path variables, here's a way to execute the Python script through your batch file:

start C:\Python27\ArcGIS10.2\python.exe C:\Path\To\Script\myScript.py
PAUSE


It will open up the Python command window, so I'd recommend wrapping your script in something like this to keep the window open for error checking and printing outputs to the console:

import traceback

try:

    # Your script here
    
except:
    traceback.print_exc()

finally:
    raw_input("Press any key to close this window")
0 Kudos