Reputation: 69
I'm having problems calling an external command from within a python routine. I've written code before that calls simple commands but this one is a bit trickier and I'm just floundering around and getting nowhere.
The command is one of the GMT (Generic Mapping Tools) commands - "gmtselect" which takes a file of latitude/longitude coordinates and sees which ones are within a polygon defined by a series of lat/long points in a separate file.
If we call these two file "points.txt" and "polygon.txt" then from the command line the call would be:
gmtselect <polygon.txt -Fpolygon.txt
I've tried various ways but cannot see how to do this using subprocess.Popen
Any informed suggestions?
Upvotes: 1
Views: 1157
Reputation: 993
import subprocess
with open('filename.txt') as f:
subprocess.run(['gmtselect', '-Fother.txt'], stdin=f)
Upvotes: 2