I'm running arcPy commands from a C# script i.e.

RunPythonScript("arcpy.Delete_management(\"C:\\\\Temp\\\\NW\\\\land.gdb\", \"Table\")");

private static void RunPythonScript(string script)
                Stopwatch stpw = new Stopwatch();

                string pyfile = "C:\\Temp\\cmd.py";

                StreamWriter sw = new StreamWriter(pyfile);
                sw.WriteLine("import arcpy");
                sw.WriteLine("from arcpy import env");

The problem is this makes debugging very difficult without viewing error messages produced in Python. How can I write errors to a log file or otherwise view the errors being produced by my ArcPy commands?


2 Answers 2


It is unclear how you are running your Python script from .NET, so I will assume that you are using System.Diagnostics.Process

Process proc = new Process()
    StartInfo = new ProcessStartInfo()
        FileName = "C:\Python27\ArcGIS10.4\python.exe";
        Arguments = "<your python file>"
        RedirectStandardError = true; //error output
        RedirectStandardOutput = true; //other output

string all_error_output = proc.StandardError.ReadToEnd();  //read any errors
string all_normal_output = proc.StandardOutput.ReadToEnd();  //read any output

An alternative solution was to access my cmd.py which passes the python command being processed and copying that command and running it in the python command window in ArcMap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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