1

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Shapi
  • 5,493
  • 4
  • 28
  • 39
  • A complete example is examined [here](http://stackoverflow.com/a/5740673/230513). – trashgod Dec 03 '13 at 10:41
  • im kinda new at unix console, its a bit hard to me to understand the argumentens they are passing into the process builder – Shapi Dec 03 '13 at 10:55

1 Answers1

1

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");
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • "[2013-12-03 11:58:17] Unexpected extra commandline arguments [2013-12-03 11:58:17] Unexpected extra commandline arguments " i get this output And if i place this: ProcessBuilder pb = new ProcessBuilder("bash","-c",/User/me/path/to/Binaryfile/binfile,"-o http://xx.xxx.xx.xxx:xxxx" ,"-u xxxxx"," -p xxxxx" );, the outout is: Error opening terminal: unknown. – Shapi Dec 03 '13 at 11:58
  • I don't understand why you're running a sub-shell; see updated example. – trashgod Dec 03 '13 at 12:23
  • i have a binary file, and when im running it i have to insert some args in the shell, and i want to start the binary with fixed args with the java – Shapi Dec 03 '13 at 14:04
  • with your code i get this output :Error opening terminal: unknown...I dont need to call the bash or -c? – Shapi Dec 03 '13 at 14:25
  • PS: Dont forget the fact im doing this on a macOS – Shapi Dec 03 '13 at 14:31
  • Same here; for reference, I tested with `new ProcessBuilder("head", "-n 10", "build.xml")`. – trashgod Dec 03 '13 at 17:18