Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm starting to learn Python and batch files. I have a Python script which selects data by location and exports the selection to a new feature class. The script runs just fine - included in this script I have the following lines:

matchCount = int(arcpy.GetCount_management(featureLayer).getOutput(0))

print str(matchCount) + " rows exported"

When I run this script in PythonWin the print statement above is produced in the Interactive Window. When I run this script through a batch file the print statement isn't produced. At the end of my batch file I have written PAUSE so the screen doesn't disappear after running my script. Anyone have ideas on how to produce my print statement in command line?

Regards, Patty

share|improve this question
1  
you could invoke your script in the command prompt, and then it wont exit upon completion. You could click Start->Run, type "cmd" and hit enter. Then navigate to your script and run it. –  Allan Adair Sep 15 '11 at 16:45
    
Is it possible for you to invoke your python script from the command line without running the batch file? –  Allan Adair Sep 15 '11 at 18:26
    
Thank you, Allan. I was able to run my .bat file as you suggested but what I'm really after is getting the print statement in my Python script to print in the command line. I imagine that is possible? Within my Python script I want to print a count: matchCount = int(arcpy.GetCount_management(featureLayer).getOutput(0)) print str(matchCount) + " rows exported" When I run my batch file in command line the window states: Ran myscript.py Press any key to continue... I would like the print statement from my script, "X rows exported", to also print in the window as well. Thank you. –  Patty Jula Sep 15 '11 at 18:33
2  
I would suggest not using a batch file to invoke python scripts. Instead I would try invoking your python script directly from the command prompt. Any external functionality in the batch file can be coded in the Python script –  Allan Adair Sep 15 '11 at 18:40
add comment

2 Answers

up vote 0 down vote accepted

Can you show us the contents of your batch file please?

(Btw, recommended practice is to use arcpy.AddMessage rather than print, for portability between command line/batch files and arcmap. But print is fine if you don't want your message to display inside arcmap.)

share|improve this answer
    
Ah, thank you. I put an arcpy.AddMessage in my Python script and got that statement to print the matchCount when I ran the batch file. Below is my batch file if you were curious. Thanks again. @ECHO OFF REM Runs myScript.py C:\Python26\ArcGIS10.0\python.exe C:\project\python\myScript.py ECHO Ran myScript.py PAUSE –  Patty Jula Sep 16 '11 at 14:52
    
Glad that helped, still weird that print doesn't work. Have you tried removing the @ECHO OFF line and calling your script with the -u argument: C:\Python26\ArcGIS10.0\python.exe -u C:\project\python\myScript.py Kind of stabs in the dark but I have similar batch scripts and it works for me... –  Sideshow Bob Sep 19 '11 at 11:14
    
OK, I removed the @ECHO OFF from my .bat file and inserted "-u" as you suggested. I also modified my script so the arcpy.AddMessage was commented out and inserted my print line. The batch file ran and my print statement displayed. Now I know two ways of printing statements in command line. Thank you. –  Patty Jula Sep 19 '11 at 21:13
add comment

An easier way for you to do this, is to set up Eclipse to work with PyDev and you can run your code and debug it there. You actually debig it there, putting stops and watches in the code, to interogate the objects.

That's my advice.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.