Search code examples
javamacosruntime.execprocessbuilder

ProcessBuilder on OSX


I am able to successfully execute this on windows:

builder = new ProcessBuilder("cmd.exe", "/c", "nmap " + ipRange, "&cd");

But this on OSX fails:

builder = new ProcessBuilder("/usr/local/bin/nmap", ipRange);

With the error:

"Starting Nmap 5.51 ( http://nmap.org ) at 2012-03-22 09:51 PDT

Invalid host expression: 127.0.0.1 -p T:80 -- colons only allowed in IPv6 addresses, and then you need the -6 switch

QUITTING!"

What is the correct way to create that ProcessBuilder for OSX? Thanks


Solution

  • I'm guessing you are trying to pass two separate parameters as one String in ipRange. The ProcessBuilder probably wraps the ipRange String with quotes and messes up the command syntax. You need to add all parameters separately

    Not like this:

    new ProcessBuilder("/usr/local/bin/nmap", "-foo foo -bar bar");
    

    but like this:

    new ProcessBuilder("/usr/local/bin/nmap", "-foo", "foo", "-bar", "bar");