[英]Execute Unix command from Java
在Java中如何執行以下shell命令:
osmosis --read-xml file="planet-latest.osm" --bounding-polygon file="country.poly" --write-xml file="australia.osm"
我試着用這段代碼執行它:
Process proc = Runtime.getRuntime().exec("osmosis --read-xml file="planet-latest.osm" --bounding-polygon file="country.poly" --write-xml file="australia.osm"");
InputStream output = proc.getInputStream();
但似乎Unix命令沒有執行。
您可能需要指定滲透的完整路徑。
使用Runtime是一種不推薦的執行命令的方法。 看看ProcessBuilder
嘗試逃避雙重“
Process proc = Runtime.getRuntime().exec("osmosis --read-xml file=\\"planet-latest.osm\\" --bounding-polygon file=\\"country.poly\\" --write-xml file=\\"australia.osm\\"")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.