简体   繁体   中英

terminal and subprocess.run() show different behaviors for a command (osmfilter)

I am seeing a peculiar behavior with osmfilter ( https://wiki.openstreetmap.org/wiki/Osmfilter ) which can be installed with the following command:

$ sudo apt-get install osmctools

Lets assume I exported map.osm for a region from https://www.openstreetmap.org and I want to filter only highways from that file. The command I can use is:

$ osmfilter map.osm --keep='highway' > highways_terminal.osm

The file highways_terminal.osm contains info about the highways. I then tried to use Python to do the same with subprocess.run():

import subprocess

cmd = ["osmfilter", "map.osm", "--keep='highway'"]
resp = subprocess.run(cmd, capture_output=True, text=True)

with open("highways_subprocess.osm", "w") as fp:
    fp.write(resp.stdout)

But, highways_subprocess.osm contains no information other than "bounds".

Am I handling the quotes incorrectly?

I was having this problem (10 months later) and fixed it as

cmd = "osmfilter map.osm --keep='highway' -o=highways_subprocess.osm"
subprocess.check_call(cmd, shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM