<?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 Cannot start subprocess or os.system(command) with 'import arcpy' in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cannot-start-subprocess-or-os-system-command-with/m-p/1006791#M59208</link>
    <description>&lt;P&gt;I need to call a python script from another script, and not wait (this is a script to start multiple other scripts).&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have three different methods of calling the script - execfile(), os.system(), and subprocess.popen().&amp;nbsp; &amp;nbsp;These all work - but, the first one forces the program to wait; and the other ones will fail when it tries to import arcpy.&amp;nbsp; I suspect it is something to do with my 64-bit background geoprocessing, which I just reinstalled this morning.&amp;nbsp; &amp;nbsp;The error that occurs when importing arcpy is this:&lt;/P&gt;&lt;P&gt;"Traceback (most recent call last):&lt;BR /&gt;File "f:\scratch\test.py", line 5, in &amp;lt;module&amp;gt;&lt;BR /&gt;import arcpy&lt;BR /&gt;File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\__init__.py", line 22, in &amp;lt;module&amp;gt;&lt;BR /&gt;from arcpy.geoprocessing import gp&lt;BR /&gt;File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in &amp;lt;module&amp;gt;&lt;BR /&gt;from _base import *&lt;BR /&gt;File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\geoprocessing\_base.py", line 14, in &amp;lt;module&amp;gt;&lt;BR /&gt;import arcgisscripting&lt;BR /&gt;ImportError: DLL load failed: %1 is not a valid Win32 application."&lt;/P&gt;&lt;P&gt;I only have one installation of Python.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attaching two scripts:&amp;nbsp; test1.py will call test.py with the three different methods - if they are successful, they will write out text files indicating which method was used.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't attach my scripts here, so they are pasted below:&amp;nbsp; The called script is commented out.&amp;nbsp; I'd sure appreciate any help with this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#MAIN SCRIPT&lt;/P&gt;&lt;P&gt;import os&lt;BR /&gt;import subprocess&lt;BR /&gt;import sys&lt;BR /&gt;#import arcpy #works whether or not this is commented&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;''' script that's called by 3 methods below:&lt;BR /&gt;#script f:\\scratch\\test.py&lt;/P&gt;&lt;P&gt;import sys&lt;BR /&gt;import time&lt;BR /&gt;outFile = sys.argv[1]&lt;BR /&gt;print (outFile)&lt;BR /&gt;import arcpy #if this is commented, all three methods work; otherwise only execfile works&lt;BR /&gt;print ("writing file")&lt;BR /&gt;newInputFile = "f:\\scratch\\" + outFile + ".txt"&lt;BR /&gt;inputfile = open(newInputFile, "w")&lt;BR /&gt;inputfile.close()&lt;BR /&gt;print(sys.version)&lt;BR /&gt;print("sleeping")&lt;BR /&gt;time.sleep(5)&lt;/P&gt;&lt;P&gt;'''&lt;/P&gt;&lt;P&gt;print ("execfile here:")&lt;BR /&gt;sys.argv = ['test.py','file_from_execfile']&lt;BR /&gt;execfile("f:\\scratch\\test.py")&lt;/P&gt;&lt;P&gt;print("")&lt;/P&gt;&lt;P&gt;command = 'python f:\\scratch\\test.py file_from_command'&lt;BR /&gt;print ("command here:")&lt;BR /&gt;os.system(command)&lt;/P&gt;&lt;P&gt;script = "f:\\scratch\\test.py"&lt;BR /&gt;pythonExePath = r'C:\Python27\ArcGISx6410.8\python.exe'&lt;BR /&gt;pid = subprocess.Popen([pythonExePath, script, 'file_from_subprocess'], shell=False) # Call subprocess&lt;/P&gt;&lt;P&gt;print ("done")&lt;/P&gt;</description>
    <pubDate>Thu, 03 Dec 2020 20:54:37 GMT</pubDate>
    <dc:creator>KevinAndras</dc:creator>
    <dc:date>2020-12-03T20:54:37Z</dc:date>
    <item>
      <title>Cannot start subprocess or os.system(command) with 'import arcpy'</title>
      <link>https://community.esri.com/t5/python-questions/cannot-start-subprocess-or-os-system-command-with/m-p/1006791#M59208</link>
      <description>&lt;P&gt;I need to call a python script from another script, and not wait (this is a script to start multiple other scripts).&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have three different methods of calling the script - execfile(), os.system(), and subprocess.popen().&amp;nbsp; &amp;nbsp;These all work - but, the first one forces the program to wait; and the other ones will fail when it tries to import arcpy.&amp;nbsp; I suspect it is something to do with my 64-bit background geoprocessing, which I just reinstalled this morning.&amp;nbsp; &amp;nbsp;The error that occurs when importing arcpy is this:&lt;/P&gt;&lt;P&gt;"Traceback (most recent call last):&lt;BR /&gt;File "f:\scratch\test.py", line 5, in &amp;lt;module&amp;gt;&lt;BR /&gt;import arcpy&lt;BR /&gt;File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\__init__.py", line 22, in &amp;lt;module&amp;gt;&lt;BR /&gt;from arcpy.geoprocessing import gp&lt;BR /&gt;File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in &amp;lt;module&amp;gt;&lt;BR /&gt;from _base import *&lt;BR /&gt;File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\geoprocessing\_base.py", line 14, in &amp;lt;module&amp;gt;&lt;BR /&gt;import arcgisscripting&lt;BR /&gt;ImportError: DLL load failed: %1 is not a valid Win32 application."&lt;/P&gt;&lt;P&gt;I only have one installation of Python.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attaching two scripts:&amp;nbsp; test1.py will call test.py with the three different methods - if they are successful, they will write out text files indicating which method was used.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't attach my scripts here, so they are pasted below:&amp;nbsp; The called script is commented out.&amp;nbsp; I'd sure appreciate any help with this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#MAIN SCRIPT&lt;/P&gt;&lt;P&gt;import os&lt;BR /&gt;import subprocess&lt;BR /&gt;import sys&lt;BR /&gt;#import arcpy #works whether or not this is commented&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;''' script that's called by 3 methods below:&lt;BR /&gt;#script f:\\scratch\\test.py&lt;/P&gt;&lt;P&gt;import sys&lt;BR /&gt;import time&lt;BR /&gt;outFile = sys.argv[1]&lt;BR /&gt;print (outFile)&lt;BR /&gt;import arcpy #if this is commented, all three methods work; otherwise only execfile works&lt;BR /&gt;print ("writing file")&lt;BR /&gt;newInputFile = "f:\\scratch\\" + outFile + ".txt"&lt;BR /&gt;inputfile = open(newInputFile, "w")&lt;BR /&gt;inputfile.close()&lt;BR /&gt;print(sys.version)&lt;BR /&gt;print("sleeping")&lt;BR /&gt;time.sleep(5)&lt;/P&gt;&lt;P&gt;'''&lt;/P&gt;&lt;P&gt;print ("execfile here:")&lt;BR /&gt;sys.argv = ['test.py','file_from_execfile']&lt;BR /&gt;execfile("f:\\scratch\\test.py")&lt;/P&gt;&lt;P&gt;print("")&lt;/P&gt;&lt;P&gt;command = 'python f:\\scratch\\test.py file_from_command'&lt;BR /&gt;print ("command here:")&lt;BR /&gt;os.system(command)&lt;/P&gt;&lt;P&gt;script = "f:\\scratch\\test.py"&lt;BR /&gt;pythonExePath = r'C:\Python27\ArcGISx6410.8\python.exe'&lt;BR /&gt;pid = subprocess.Popen([pythonExePath, script, 'file_from_subprocess'], shell=False) # Call subprocess&lt;/P&gt;&lt;P&gt;print ("done")&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 20:54:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-start-subprocess-or-os-system-command-with/m-p/1006791#M59208</guid>
      <dc:creator>KevinAndras</dc:creator>
      <dc:date>2020-12-03T20:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot start subprocess or os.system(command) with 'import arcpy'</title>
      <link>https://community.esri.com/t5/python-questions/cannot-start-subprocess-or-os-system-command-with/m-p/1006795#M59209</link>
      <description>&lt;P&gt;There are limits to 64 background geoprocessing.&amp;nbsp; Most would move to ArcGIS Pro&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/64bit-background.htm" target="_blank"&gt;Background Geoprocessing (64-bit)—ArcMap | Documentation (arcgis.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 21:15:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-start-subprocess-or-os-system-command-with/m-p/1006795#M59209</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-12-03T21:15:37Z</dc:date>
    </item>
  </channel>
</rss>

