1

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.

3 Answers 3

2

You may need to specify the complete path to osmosis.

Sign up to request clarification or add additional context in comments.

2 Comments

Also, don't forget to escape double quotes. Or better, use overloaded exec method with arrays to pass arguments.
In addition, I would recommend that he use Commons-Exec instead of Runtime.exec() or ProcessBuilder.
1

Using the Runtime is a deprecated way of executing commands. Take a look at ProcessBuilder

Comments

1

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\"")

1 Comment

in Java, a String literal has to start with " (double quotes), your example is starting from a single quote '.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.