Java questioner
Java questioner

Reputation: 157

Execute Unix command from Java

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.

Upvotes: 1

Views: 3575

Answers (3)

Simiil
Simiil

Reputation: 2311

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

Upvotes: 1

LordDoskias
LordDoskias

Reputation: 3191

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

Upvotes: 1

Brian Knoblauch
Brian Knoblauch

Reputation: 21349

You may need to specify the complete path to osmosis.

Upvotes: 2

Related Questions