从Java执行Unix命令

时间:2011-10-04 15:21:21

标签: java shell unix

在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命令。

3 个答案:

答案 0 :(得分:2)

您可能需要指定渗透的完整路径。

答案 1 :(得分:1)

使用Runtime是一种不推荐的执行命令的方法。看看ProcessBuilder

答案 2 :(得分:1)

尝试逃避双重“

Process proc = Runtime.getRuntime().exec("osmosis --read-xml file=\"planet-latest.osm\" --bounding-polygon file=\"country.poly\" --write-xml file=\"australia.osm\"")

相关问题