Newbie question: script works in ArcGIS Python window but not from DOS prompt

666
4
06-29-2011 04:39 PM
MarchandDupris
New Contributor
OK, I give up: Here's a very simple script which, when entered line by line in the Python window within ArcGIS 10, works just fine. It reports, correctly, that the specified feature class exists. However, when the exact same file is run from the command line, on the same machine, in the same session, it reports the feature class does not exist. No Python errors are reported in either environment. The FC lives in an SDE/SQL Server environment on a remote server, has real data, makes real maps, ... Is it a permissions issue somehow? Is there something else I need to set in the environment when running it from the command line? Other?

= M =


import arcpy
from arcpy import env

env.workspace = "Database Connections/Whatever - Else"
fc = "Testenv.SDE.testFC"

if arcpy.Exists(fc):
     print "This exists: %s" % fc
else:
     print "This does not exist: %s" % fc
Tags (2)
0 Kudos
4 Replies
JasonScheirer
Occasional Contributor III
Try adding .sde to the end of the name.
0 Kudos
MarchandDupris
New Contributor
Jason,

Thanks for your reply. It wasn't clear which name the '.sde' should be added to, so I tried the various combinations of the env.workspace and the 'fc' variable. Neither worked. Which did you mean?
When working on this problem some more within ArcGIS 10.0 some more, I noticed something else. Within ArcGIS the script only works if I have an MXD file open which uses the feature class in question. If I do a "File / New / Blank map" and run the script as is, it says the feature class does not exist. This makes me wonder if there are other environment/permission/security parameters which must be set somehow within the script itself. My goal here is to have a stand-alone Python script which can be run independently of an ArcGIS session. Any hints on how to make that happen are most welcome.

= M =
0 Kudos
deleted-user-1T_bOHag6M8d
Occasional Contributor
I wonder if it's necessary to give the complete path to the SDE connection file, not just "Database Connections..." but "C:/Documents and Settings/.../Database Connections/..." or wherever the location is.
0 Kudos
SigiSharp
New Contributor
OK, I give up: Here's a very simple script which, when entered line by line in the Python window within ArcGIS 10, works just fine. It reports, correctly, that the specified feature class exists. However, when the exact same file is run from the command line, on the same machine, in the same session, it reports the feature class does not exist. No Python errors are reported in either environment. The FC lives in an SDE/SQL Server environment on a remote server, has real data, makes real maps, ... Is it a permissions issue somehow? Is there something else I need to set in the environment when running it from the command line? Other?

= M =


import arcpy
from arcpy import env

env.workspace = "Database Connections/Whatever - Else"
fc = "Testenv.SDE.testFC"

if arcpy.Exists(fc):
     print "This exists: %s" % fc
else:
     print "This does not exist: %s" % fc


if you set the database connection as the default gdb in arccatalog
then 
fc = env.workspace
print "%s" % fc

you will see exactly what it expects for the workspace

fcs = arcpy.listfeatureclasses()
print fcs

will return the list of feature classes in the workspace

lds = arcpy.listdatasets()
print lds

will return a list of the datasets
0 Kudos