<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Arcpy script behaves differently in command prompt and C# in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-script-behaves-differently-in-command-prompt/m-p/41461#M3305</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an Arcpy script that is having issues with escape backslashes in a folder name when passed in from a C# Process command and this does not happen in command prompt. I run both on the same server so would expect both to work the same when opassed in the same data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code that is behaving differently is below (apolgies in advance as I cannot find the command to embed source code in a nice way):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "[INFO]&amp;nbsp; GGF - Output_dir initially is " + output_dir + " at " + str(datetime.datetime.now()) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; win32evtlogutil.ReportEvent(appName,0,0,win32evtlog.EVENTLOG_INFORMATION_TYPE,[message])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## workaround to deal with C# putting in extra \ in folder names&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output_dir_frm = output_dir.replace("&lt;A&gt;\\\\&lt;/A&gt;", "\\");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "[INFO]&amp;nbsp; GGF - Output_dir formatted is " + output_dir_frm + " at " + str(datetime.datetime.now()) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; win32evtlogutil.ReportEvent(appName,0,0,win32evtlog.EVENTLOG_INFORMATION_TYPE,[message])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, the statement in question is in bold. When I call from command prompt, the 3rd argument is the one I am trying to fix:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"D:\\TFS\\Pegasus_MWingfield\GenerateGeorouteFilesNetwork.py" "C:\\Users\\mark.r.wingfield\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\&lt;/P&gt;&lt;P&gt;\DWOP.SDE" 3903 &lt;STRONG&gt;"&lt;A&gt;\\\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\\&lt;/A&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is simply to mimic what is happening in the C# call. In C#, I am using the 32 bit version of Python.exe (the 64 bit doesn't work at all) and the 3rd argument is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"&lt;A&gt;\\\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\\&lt;/A&gt;" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looks the same so far.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When running the command prompt version, the message values created are as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir initially is &lt;A&gt;\\\\RMGAPPODC047V\\PegasusTier1DevData$\\a&lt;/A&gt;lstalba\\Universal\ at 2014-09-16 14:40:32.242000&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir formatted is&lt;SPAN style="color: #303030;"&gt; &lt;A href="https://community.esri.com/"&gt;&lt;SPAN style="color: #303030;"&gt;\\RMGAPPODC047V\PegasusTier1DevData$\alsta&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;lba\Universal\ at 2014-09-16 14:40:32.244000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is fine as it correctly removes escape values in every occurrence.&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;When running from a C# Process command:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir initially is \\\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\" at 2014-09-16 16:03:11.289000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir &lt;SPAN style="color: #303030;"&gt;formatted is &lt;A href="https://community.esri.com/"&gt;&lt;SPAN style="color: #303030;"&gt;\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\&lt;/SPAN&gt;&lt;/A&gt;"&lt;/SPAN&gt; at 2014-09-16 16:03:11.290000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, using exactly the same python script (I have no other!!!), this time it seems to treat the "&lt;A&gt;\\\\&lt;/A&gt;" as physical backslashes and so only replaces that first set of 4 backslashes. This then means the folder format is invalid and my process fails when trying to use this folder name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is cleard from the output that the string to be formtted is identical in each case but the result of the arcpy replace is different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any means of printing some information from within the script that will show what version of python.exe is being run as this seems to be the only explanation I can think of.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once again, there is only one version of my script and I can guarantee that this is the version called from the C# (indeed, when it was failing and i needed to identfiy the issue, I put the command in the one script, along with the before and after message, and reran from both environments, thus proving it is the one script.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Sep 2014 15:11:14 GMT</pubDate>
    <dc:creator>MarkWingfield</dc:creator>
    <dc:date>2014-09-16T15:11:14Z</dc:date>
    <item>
      <title>Arcpy script behaves differently in command prompt and C#</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-script-behaves-differently-in-command-prompt/m-p/41461#M3305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an Arcpy script that is having issues with escape backslashes in a folder name when passed in from a C# Process command and this does not happen in command prompt. I run both on the same server so would expect both to work the same when opassed in the same data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code that is behaving differently is below (apolgies in advance as I cannot find the command to embed source code in a nice way):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "[INFO]&amp;nbsp; GGF - Output_dir initially is " + output_dir + " at " + str(datetime.datetime.now()) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; win32evtlogutil.ReportEvent(appName,0,0,win32evtlog.EVENTLOG_INFORMATION_TYPE,[message])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## workaround to deal with C# putting in extra \ in folder names&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output_dir_frm = output_dir.replace("&lt;A&gt;\\\\&lt;/A&gt;", "\\");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "[INFO]&amp;nbsp; GGF - Output_dir formatted is " + output_dir_frm + " at " + str(datetime.datetime.now()) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; win32evtlogutil.ReportEvent(appName,0,0,win32evtlog.EVENTLOG_INFORMATION_TYPE,[message])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, the statement in question is in bold. When I call from command prompt, the 3rd argument is the one I am trying to fix:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"D:\\TFS\\Pegasus_MWingfield\GenerateGeorouteFilesNetwork.py" "C:\\Users\\mark.r.wingfield\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\&lt;/P&gt;&lt;P&gt;\DWOP.SDE" 3903 &lt;STRONG&gt;"&lt;A&gt;\\\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\\&lt;/A&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is simply to mimic what is happening in the C# call. In C#, I am using the 32 bit version of Python.exe (the 64 bit doesn't work at all) and the 3rd argument is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"&lt;A&gt;\\\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\\&lt;/A&gt;" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looks the same so far.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When running the command prompt version, the message values created are as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir initially is &lt;A&gt;\\\\RMGAPPODC047V\\PegasusTier1DevData$\\a&lt;/A&gt;lstalba\\Universal\ at 2014-09-16 14:40:32.242000&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir formatted is&lt;SPAN style="color: #303030;"&gt; &lt;A href="https://community.esri.com/"&gt;&lt;SPAN style="color: #303030;"&gt;\\RMGAPPODC047V\PegasusTier1DevData$\alsta&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;lba\Universal\ at 2014-09-16 14:40:32.244000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is fine as it correctly removes escape values in every occurrence.&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;When running from a C# Process command:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir initially is \\\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\" at 2014-09-16 16:03:11.289000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[INFO]&amp;nbsp; GGF - Output_dir &lt;SPAN style="color: #303030;"&gt;formatted is &lt;A href="https://community.esri.com/"&gt;&lt;SPAN style="color: #303030;"&gt;\\RMGAPPODC047V\\PegasusTier1DevData$\\alstalba\\Universal\&lt;/SPAN&gt;&lt;/A&gt;"&lt;/SPAN&gt; at 2014-09-16 16:03:11.290000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, using exactly the same python script (I have no other!!!), this time it seems to treat the "&lt;A&gt;\\\\&lt;/A&gt;" as physical backslashes and so only replaces that first set of 4 backslashes. This then means the folder format is invalid and my process fails when trying to use this folder name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is cleard from the output that the string to be formtted is identical in each case but the result of the arcpy replace is different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any means of printing some information from within the script that will show what version of python.exe is being run as this seems to be the only explanation I can think of.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once again, there is only one version of my script and I can guarantee that this is the version called from the C# (indeed, when it was failing and i needed to identfiy the issue, I put the command in the one script, along with the before and after message, and reran from both environments, thus proving it is the one script.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 15:11:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-script-behaves-differently-in-command-prompt/m-p/41461#M3305</guid>
      <dc:creator>MarkWingfield</dc:creator>
      <dc:date>2014-09-16T15:11:14Z</dc:date>
    </item>
  </channel>
</rss>

