<?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 Re: How can I create a arcpy script/tool to open a file? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312383#M24305</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Ian.&amp;nbsp; Quite a bit to look thru and test (first simple test didn't).&amp;nbsp; I'll let you know how it works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Nov 2015 20:45:19 GMT</pubDate>
    <dc:creator>RebeccaStrauch__GISP</dc:creator>
    <dc:date>2015-11-25T20:45:19Z</dc:date>
    <item>
      <title>How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312381#M24303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In my custom toolbar, I have series of steps that need to be processed in order. Between two of these steps, it is necessary to do quite a bit of manual editing (in ArcMap...polygons)....based on some input from staff, and most likely from some paper sources.&amp;nbsp; I will have a document of some type (.doc, .txt or similar) will some detailed instructions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way that I can open a document thru a python/arcpy script and add it to my toolbar?&amp;nbsp; If I can get the script, I should be able to do the toolbar/addin part, but I haven't figure out how to "open" a readme type file thru a toolbox script/button.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In theory, I would probably not even have any input parameters, and I would hard code the (relative) path to the document.&amp;nbsp; I've started searching for solutions, but thought I would throw this question out there in case a solution already exists.&amp;nbsp; I have not written any specific code for this problem yet (i.e., nothing worth sharing).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I can figure this out, I will use this in several of my addin projects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cross-posting:&amp;nbsp; &lt;A href="https://community.esri.com/space/2030"&gt;Developers&lt;/A&gt;​ &lt;A href="https://community.esri.com/space/2087"&gt;Geoprocessing&lt;/A&gt;​ &lt;A href="https://community.esri.com/group/4114"&gt;Python AddIns&lt;/A&gt;​ &lt;A href="https://community.esri.com/group/1519"&gt;python snippets&lt;/A&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 20:26:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312381#M24303</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-11-25T20:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312382#M24304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python" title="http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python"&gt;http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 20:38:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312382#M24304</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-11-25T20:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312383#M24305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Ian.&amp;nbsp; Quite a bit to look thru and test (first simple test didn't).&amp;nbsp; I'll let you know how it works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 20:45:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312383#M24305</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-11-25T20:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312384#M24306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If using windows, this is probably the easiest solution.&amp;nbsp; Some people on stackexchange get a little overly pythonic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2/library/os.html#os.startfile" title="https://docs.python.org/2/library/os.html#os.startfile"&gt;15.1. os — Miscellaneous operating system interfaces — Python 2.7.11rc1 documentation&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 20:49:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312384#M24306</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-11-25T20:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312385#M24307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I got it to work in the python window, if I hard code the path.&amp;nbsp; I now have the script created, and it works with my relative path.&amp;nbsp;&amp;nbsp; My .txt file is in the same folder as all my scripts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the quick response Ian.&amp;nbsp; For some reason I just couldn't come up with a good search string. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oh...and for those that care, I added the script to my toolbox....no parameters for right now and it opens my txt file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import arcpy


#filename = r"C:\___bear2016\__python\Scripts\3MyTestHelp.txt"
filename = r"3MyTestHelp.txt"
os.system("start " + filename)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I don't need to import arcpy right now.....but haven't removed it yet since I may add more stuff.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:55:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312385#M24307</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2021-12-11T14:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312386#M24308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yea it took a few tries for me to find the right search.&amp;nbsp; Plenty of threads on how to open files within python, but not a bunch on launching them externally.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 20:58:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312386#M24308</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-11-25T20:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312387#M24309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;os.system()&lt;/STRONG&gt; is the old way to do it, though still okay for the "quick and dirty"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to do this the new way, which is to use &lt;A href="https://docs.python.org/2/library/subprocess.html" rel="nofollow noopener noreferrer" target="_blank"&gt;subprocess.&lt;/A&gt;​&lt;/P&gt;&lt;P&gt;The new way is more secure, as it doesn't have as much risk of &lt;A href="https://en.wikipedia.org/wiki/Code_injection" rel="nofollow noopener noreferrer" target="_blank"&gt;code injection.&lt;/A&gt;​&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import subprocess
subprocess.check_output(["cmd", "/c", "start", filename])&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The windows-only os.startfile() is also mentioned in that (excellent) stack exchange article. I didn't know about that one -- it emulates double clicking in Windows Explorer. It has the advantage of supporting files with spaces!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;os.startfile(filename)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:55:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312387#M24309</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T14:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a arcpy script/tool to open a file?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312388#M24310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Curtis.&amp;nbsp; I'll take a look at that too. Just trying to keep it all simple for the "pop up"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Nov 2015 16:22:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-arcpy-script-tool-to-open-a/m-p/312388#M24310</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-11-26T16:22:08Z</dc:date>
    </item>
  </channel>
</rss>

