Select to view content in your preferred language

ArcGIS Pro Stand Alone Scripts in Batch File

3375
6
Jump to solution
03-08-2023 02:51 PM
ModernElectric
Frequent Contributor

I am in the process of converting everything from ArcMap to ArcGIS Pro. For years, I have had a series of Batch Files that were used in Window's Task Scheduler to run dozens of Stand Alone Python scripts overnight to update my GIS data from external databases. Part of the project is to convert the code from Python 2 to Python 3. One of the items I cannot figure out is how to convert the existing BATCH files with the collection of Python 2 scripts to an executable BATCH file with Python 3 scripts. I learned how to put a script into a BATCH file and run it outside of ArcGIS Pro, but I need to add multiple Python Scripts in a single BATCH file to run them one after another, similar to what I was able to do with Python 2 (2.7). I am stuck, so any help would be great.

Thank You 

0 Kudos
1 Solution

Accepted Solutions
Tim_McGinnes
Frequent Contributor

Step 1 - Go to the folder shown in the screenshot below and verify that python.exe is there.

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe

python.jpg

If it is there then:

Step 2 - Paste the following into a batch file and run it:

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" "C:\Users\cwafstet\Documents\MODERN GIS WORKING FILES\PYTHON SCRIPTS COLLECTION\CIS DATA GIS UPDATES\CISMIS_ElectricAccounts_ActiveStatus.py"
pause

If you get an error, can you screenshot please.

View solution in original post

0 Kudos
6 Replies
MichaelVolz
Esteemed Contributor

Are you calling the python scripts from the bat file in python 2.7?  You should just have to update the python to 3.x and be able to use the same bat file to call the python scripts.  I have done this myself already.

0 Kudos
Tim_McGinnes
Frequent Contributor

Michael is right, something like this:

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" <script>.py

 

0 Kudos
ModernElectric
Frequent Contributor
C:\Python27\ArcGIS10.5\python.exe "C:\Users\cwafstet\Documents\MODERN GIS WORKING FILES\PYTHON SCRIPTS COLLECTION\CIS DATA GIS UPDATES\CISMIS_ElectricAccounts_ActiveStatus.py"

This is what my Python 2.7 call-out looks like within my BATCH file via Notepad.

Trying to rewrite it to match with the online files says is not working.

How should this look for Python 3? I know this should be very simple but is really frustrating me.

Appreciate it.

0 Kudos
Tim_McGinnes
Frequent Contributor

Step 1 - Go to the folder shown in the screenshot below and verify that python.exe is there.

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe

python.jpg

If it is there then:

Step 2 - Paste the following into a batch file and run it:

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" "C:\Users\cwafstet\Documents\MODERN GIS WORKING FILES\PYTHON SCRIPTS COLLECTION\CIS DATA GIS UPDATES\CISMIS_ElectricAccounts_ActiveStatus.py"
pause

If you get an error, can you screenshot please.

0 Kudos
ModernElectric
Frequent Contributor

Thank you Tim. That did the trick. Apparently, I had to add the path to the .EXE and the .PY in quotes. That is why it was not running.

Appreciate it

0 Kudos
MichaelVolz
Esteemed Contributor

Quotes are always needed in a file path that contains spaces.  The path to python 2.7 did not contain spaces which is why it was not previously required.

Also in my testing I have found that I needed to copy the existing bat file into a brand new bat file because Task Scheduler was randomly skipping python scripts called from the bat file.

0 Kudos