<?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: Toolbox script tool to call a 2nd script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684521#M52998</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/8829"&gt;Luke Pinner&lt;/A&gt;‌ you're correct, the subprocess module did work the issue was I was referencing a network share using \&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;\servername\path\to\script.py&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;and I forgot to include the "r" before the path.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;once changing my 2nd script path to...&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;r"\\servername\path\to\folder\script.py"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;it works as expected. Thank you and &lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt;‌ for the insight on subprocess &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Dec 2018 12:49:16 GMT</pubDate>
    <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
    <dc:date>2018-12-04T12:49:16Z</dc:date>
    <item>
      <title>Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684514#M52991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a basic Script Tool that works 100% of the time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recently wanted to add a final function that would call a 2nd python script after the script tool is completed. The 2nd script is not a toolbox script just a standalone python file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;os.system('script.py')&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I get no errors after running the script with the new function but it doesn't&amp;nbsp;appear the 2nd script is being called successfully.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;note:&lt;/STRONG&gt; I did put the script.py file in the same directory as the toolbox script&lt;/P&gt;&lt;P&gt;Is this a limitation to ArcGIS Toolbox scripts or am I missing something?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2018 18:30:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684514#M52991</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2018-11-30T18:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684515#M52992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;os.system is not the best way to run another process, that's what the subprocess module is for.&amp;nbsp; However, I wouldnt reccommend this for running python scripts, It's much easier and more flexible to turn your script into a module, i.e wrap your script in a function, import the module, then call the function. Can't go into detail as I'm typing this on my phone.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Dec 2018 04:04:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684515#M52992</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2018-12-01T04:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684516#M52993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the issue with wrapping my 2nd script into a function is the execution of this 2nd script sends automated emails to a list of users. The library (&lt;STRONG&gt;SMTPlib&lt;/STRONG&gt;) for some reason NEVER works inside AcMAP or PRO. It always fails. My only work around was to separate the email function into a standalone .py file outside of the tool and have it called from within the toolbox script.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will give the sub process module a try when I get back to work on Monday.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Dec 2018 13:43:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684516#M52993</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2018-12-01T13:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684517#M52994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;script_stdout_output &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;check_output&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exec_prefix&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'python.exe'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'your_2nd_script.py'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'arg1'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'arg2'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'...'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'argN'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:47:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684517#M52994</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-12T04:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684518#M52995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;returns no errors but does not execute the 2nd script...&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Dec 2018 12:59:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684518#M52995</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2018-12-03T12:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684519#M52996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Luke that using subprocess is the way to go.&amp;nbsp; What if your second script does something very basic like open a file and write a line to it, does it work then?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Dec 2018 14:59:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684519#M52996</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-12-03T14:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684520#M52997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If there's no errors then subprocess is working fine. It's your script that's the issue.&amp;nbsp; What does `script_stdout_output` contain? Do you have any error handling that hiding any errors?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2018 04:26:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684520#M52997</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2018-12-04T04:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox script tool to call a 2nd script</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684521#M52998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/8829"&gt;Luke Pinner&lt;/A&gt;‌ you're correct, the subprocess module did work the issue was I was referencing a network share using \&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;\servername\path\to\script.py&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;and I forgot to include the "r" before the path.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;once changing my 2nd script path to...&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;r"\\servername\path\to\folder\script.py"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;it works as expected. Thank you and &lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt;‌ for the insight on subprocess &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2018 12:49:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-script-tool-to-call-a-2nd-script/m-p/684521#M52998</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2018-12-04T12:49:16Z</dc:date>
    </item>
  </channel>
</rss>

