HOW TO

Run multiple Python scripts from a single primary script

Last Published: September 14, 2020

Summary

Instructions provided give scripting examples that demonstrate how to use Python's subprocess module to spawn a new process while providing inputs to and retrieving outputs from the secondary script.

The subprocess module is new in version 2.4 of Python and is provided as a standard module. This module intends to replace several other, older modules and functions, such as:

  • os.system
  • os.spawn*
  • os.popen*
  • popen2.*
  • commands.*

*See the Python documentation for additional information about this module.

Procedure

The following is a primary script that spawns two secondary scripts:
import os
from subprocess import *

#run secondary script 1
p = Popen([r'C:\secondaryScript1.py', "ArcView"], shell=True, stdin=PIPE, stdout=PIPE)
output = p.communicate()
print output[0]

#run secondary script 2
p = Popen([r'C:\secondaryScript2.py', "ArcEditor"], shell=True, stdin=PIPE, stdout=PIPE)
output = p.communicate()
print output[0]
 Secondary script 1
import sys, arcgisscripting
gp = arcgisscripting.create(9.3)
print gp.setproduct(sys.argv[1])
Secondary script 2
import sys, arcgisscripting
gp = arcgisscripting.create(9.3)
print gp.setproduct(sys.argv[1])

Article ID:000010647

Software:
  • ArcMap 9 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options