Passing args into a executable Unix file (MacOS)

513 views Asked by At

First of all, I had some issues on the process, but the one I want to fix is passing some terminal arguments into Java:

ProcessBuilder pb = new ProcessBuilder("bash",
    "-c",
    "/User/me/path/to/Binaryfile/binfile",
    "-o this -a is -z specific -m kind -y of -kl arguments -i want "
);

If i run with this code,

ProcessBuilder pb = new ProcessBuilder("bash",
    "-c",
    "/User/me/path/to/Binaryfile/binfile"
);

I get the execution of the binary file. Remember I'm using a Mac, and I want to run the binary with some specific args of this one. Sorry, if my English is bad.

1

There are 1 answers

6
trashgod On BEST ANSWER

In this concrete example, three arguments are passed:

  • "bash"
  • "-c"
  • "ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}'"

Unless you need the shell to interpret your arguments, you can probably do something like this:

ProcessBuilder pb = new ProcessBuilder("/User/me/path/to/Binaryfile/binfile",
    "-o xx.xxx.xx.xxx:xxxx", "-u xxxxx", "-p xxxx");