Ahmed Khan Ahmed Khan - 1 month ago 21
Java Question

Run multiple commands on processbuilder in same session of sub process

I am trying to run unix commands using java Processbuilder. It creates sub processes each time new command is given. How can i run all commands in same session ?
I am trying to implement
1. & - puts job in background
2. Fg (id) brings job in foreground
3. Jobs - display current background processes in same terminal.

How can I achieve this ?

Answer

Best way to run command simultaneously is put all command in one scrip file an and then run that script file using Processbuilder

You can pass parameters as well.

$ cat myscript
#!/bin/bash
echo "First arg: $1"
echo "Second arg: $2"
$ ./myscript hello world
First arg: hello
Second arg: world
Comments