Hi all, I have the following code: ```ProcessBuild...
# announcements
n
Hi all, I have the following code:
Copy code
ProcessBuilder("/bin/sh", "-c",
      "java -jar $jarName -f $configName ${args.joinToString(" ")} &")
      .start()
how can I redirect stdout of the child to stdout of the parent process (so I could see all the messages together) ? The following code using
inheritIO
doesn't work either:
Copy code
ProcessBuilder("/bin/sh", "-c",
        "java -jar $jarName -f $configName ${args.joinToString(" ")} &")
        .inheritIO()
        .start()
Any clue where the problem is ? Is it somehow related to the fact that the child process writes to log file ?
s
What is that & doing at the end ?
a
It starts it as a child/background process
n
To put it in the background using unix features (I know this is horrible ...)
a
Don't you have to use unix features to redirect the child's stdout?
n
Can I somehow redirect the child's stdout using kotlin ? I don't like this code to be honest ...
I mean: start some process as a child and put it background and redirect its stdout to parents stdout all using kotlin features.
s
I am not sure why you need the sh part. Isnt starting it with process builder the same as a background process?
This seems to suggest that a child process can/will outlive its parent: https://stackoverflow.com/questions/269494/how-can-i-cause-a-child-process-to-exit-when-the-parent-does
n
Hmm, that is true actually ... but we don't want to do that ...
s
Then why do you want to send it to the background ?
n
to carry on with other tasks
s
But nothing prevents your kotlin app to progress with other tasks?
n
run the subprocess in the background, do some other tasks but still watch the process - sometimes kill the child and restart it with some other parameters.
a
I think you could do the other tasks and watching the process in kotlin/newly started processes though?
n
This is all going to run in a container so my guts says that the
&
is an anti-pattern. How do I start another process in the background in kotlin > What is the kotlin way to do that ?
a
I would think that
ProcessBuilder...start()
starts the process in the background...? (Or rather just starts a new process which runs on it own etc.) So what exactly do you mean with background?
n
The main process starts the child process (which does the real job) but the parent monitors the child and kills/restarts the child when needed.