从 Java 执行 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命令没有执行。
In Java how can I execute the following shell command:
osmosis --read-xml file="planet-latest.osm" --bounding-polygon file="country.poly" --write-xml file="australia.osm"
I tried executing it with this code:
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();
but it seems that the Unix command is not executed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要指定渗透的完整路径。
You may need to specify the complete path to osmosis.
使用运行时是一种已弃用的执行命令的方式。看一下 ProcessBuilder
Using the Runtime is a deprecated way of executing commands. Take a look at ProcessBuilder
尝试转义双“
Process proc = Runtime.getRuntime().exec("osmosis --read-xml file=\"planet-latest.osm\" --bounding-polygon file=\"country.poly\ " --write-xml file=\"australia.osm\"")
try escaping the double "
Process proc = Runtime.getRuntime().exec("osmosis --read-xml file=\"planet-latest.osm\" --bounding-polygon file=\"country.poly\" --write-xml file=\"australia.osm\"")