<?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: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657581#M51165</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with &lt;A href="https://community.esri.com/migrated-users/31672" target="_blank"&gt;Shaun Walbridge&lt;/A&gt;​ - you should be able to run the python code directly. More info please.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, you can do something like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def runcmd(cmd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; A generic subprocess.Popen function to run a command which suppresses consoles on Windows
&amp;nbsp;&amp;nbsp;&amp;nbsp; Luke Pinner 2013
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.name=='nt':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Windows starts up a console when a subprocess is run from a non-console
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #app like pythonw unless we pass it a flag that says not to...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; startupinfo=subprocess.STARTUPINFO()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; startupinfo.dwFlags |= 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:startupinfo=None
&amp;nbsp;&amp;nbsp;&amp;nbsp; proc=subprocess.Popen(cmd, startupinfo=startupinfo,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stdout=subprocess.PIPE, stderr=subprocess.PIPE,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stdin=subprocess.PIPE)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.name=='nt':proc.stdin.close()
&amp;nbsp;&amp;nbsp;&amp;nbsp; stdout,stderr=proc.communicate()
&amp;nbsp;&amp;nbsp;&amp;nbsp; exit_code=proc.wait()
&amp;nbsp;&amp;nbsp;&amp;nbsp; return exit_code, stdout, stderr&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 03:50:15 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2021-12-12T03:50:15Z</dc:date>
    <item>
      <title>While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657579#M51163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I run a batch at the end of the .pyt Python Toolbox script so to do most of the process (it runs a .bat file that runs a python script.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes a Python script runs a bat runs a Python script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when using subprocess.Popen("C:/output/BatchRun.bat", shell=False) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The command prompt window opens and I guess stays open till the bat is finished. The .pyt goes ahead and ends.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to get rid of the command prompt window from opening?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 14:27:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657579#M51163</guid>
      <dc:creator>PaulHacker2</dc:creator>
      <dc:date>2016-07-08T14:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657580#M51164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you describe what you're trying to do? In most contexts, it should be possible to use Python directly to invoke the related Python script instead of needing the batch file middleman.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Jul 2016 15:48:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657580#M51164</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2016-07-09T15:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657581#M51165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with &lt;A href="https://community.esri.com/migrated-users/31672" target="_blank"&gt;Shaun Walbridge&lt;/A&gt;​ - you should be able to run the python code directly. More info please.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, you can do something like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def runcmd(cmd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; A generic subprocess.Popen function to run a command which suppresses consoles on Windows
&amp;nbsp;&amp;nbsp;&amp;nbsp; Luke Pinner 2013
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.name=='nt':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Windows starts up a console when a subprocess is run from a non-console
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #app like pythonw unless we pass it a flag that says not to...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; startupinfo=subprocess.STARTUPINFO()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; startupinfo.dwFlags |= 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:startupinfo=None
&amp;nbsp;&amp;nbsp;&amp;nbsp; proc=subprocess.Popen(cmd, startupinfo=startupinfo,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stdout=subprocess.PIPE, stderr=subprocess.PIPE,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stdin=subprocess.PIPE)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.name=='nt':proc.stdin.close()
&amp;nbsp;&amp;nbsp;&amp;nbsp; stdout,stderr=proc.communicate()
&amp;nbsp;&amp;nbsp;&amp;nbsp; exit_code=proc.wait()
&amp;nbsp;&amp;nbsp;&amp;nbsp; return exit_code, stdout, stderr&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:50:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657581#M51165</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-12T03:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657582#M51166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had a similar setup but I was hoping it would NOT 'wait'... and thus show ArcGIS as being busy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even taking the proc.wait out does not help. Looking for a true background method to allow users to keep using ArcMAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 14:54:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657582#M51166</guid>
      <dc:creator>PaulHacker2</dc:creator>
      <dc:date>2016-07-11T14:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657583#M51167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you use background geoprocessing? It's designed for this purpose, and if you install &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/64bit-background.htm#GUID-A531314F-6D93-41A5-B0E2-3722B81765CB"&gt;64-bit background geoprocessing&lt;/A&gt;, will give you the advantage of providing a 64-bit environment (e.g. access to more memory, some performance improvements on a 64-bit machine).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 21:02:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657583#M51167</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2016-07-11T21:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657584#M51168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looking into it. Thanks Shaun. It looks real interesting!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 21:14:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657584#M51168</guid>
      <dc:creator>PaulHacker2</dc:creator>
      <dc:date>2016-07-11T21:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657585#M51169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well I looked, we have no license for background &lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;geoprocessing. But can a Python script that was assembled and put into a regular .py file be submitted for nightly run somehow?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2016 13:20:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657585#M51169</guid>
      <dc:creator>PaulHacker2</dc:creator>
      <dc:date>2016-07-12T13:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657586#M51170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Background Geoprocessing, either 32-bit or 64-bit, is not a separate license.&amp;nbsp; 32-bit background geoprocessing is built into the application.&amp;nbsp; 64-bit Background Geoprocessing is a separate install, but it isn't a separate license.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2016 17:12:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657586#M51170</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-07-12T17:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657587#M51171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;The executable pythonw.exe exists for the purpose of not opening a command prompt for a subprocess.&lt;/P&gt;&lt;P&gt;I did a tech workshop at UC where I used this pattern, not in a PYT but it should be adaptable - attached.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2016 21:00:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657587#M51171</guid>
      <dc:creator>BruceHarold</dc:creator>
      <dc:date>2016-07-12T21:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: While using ArcGis Python toolbox I have a subprocess.popen.. how to stop command prompt screen from appearing while it runs?</title>
      <link>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657588#M51172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It has been a while since I worked with &lt;SPAN style="font-family: courier new,courier;"&gt;subprocess&lt;/SPAN&gt;.&amp;nbsp; There are a couple of aspects to &lt;SPAN style="font-family: courier new,courier;"&gt;runcmd()&lt;/SPAN&gt; that may be blocking, i.e., causing the wait.&amp;nbsp; If I can find some more time to investigate, I will offer a more specific suggestion if you want to address the blocking.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In the past, I have used some code that is similar to what is posted here, but I originally adapted it from &lt;A href="http://code.activestate.com/recipes/409002-launching-a-subprocess-without-a-console-window/" rel="nofollow noopener noreferrer" target="_blank"&gt;Launching a subprocess without a console window (Python recipe)&lt;/A&gt;.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import subprocess

def launchWithoutConsole(command, args=None):
&amp;nbsp;&amp;nbsp;&amp;nbsp; SI = subprocess.STARTUPINFO()
&amp;nbsp;&amp;nbsp;&amp;nbsp; SI.dwFlags |= subprocess.STARTF_USESHOWWINDOW
&amp;nbsp;&amp;nbsp;&amp;nbsp; return subprocess.Popen([command] + [a for a in args or []],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; startupinfo = SI)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Part of this recipe relies on passing back the &lt;SPAN style="font-family: courier new,courier;"&gt;subprocess.Popen&lt;/SPAN&gt; object instead of relying on it to finish within the function.&amp;nbsp; If I want to call it and forget or ignore any feedback, errors, etc...; I call the function and don't assign the results to any variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All of this said, I think calling a batch file to call a Python script is not a good workflow for the OP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:50:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/while-using-arcgis-python-toolbox-i-have-a/m-p/657588#M51172</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T03:50:17Z</dc:date>
    </item>
  </channel>
</rss>

