Search code examples
bashshellprocess-substitution

Force shell script to keep command in foreground after process substitution


I have a script that needs to run a jar and redirect its output to another executable, and I need to run this with a few different parameters. I need to run it each time in isolation because it's running some tests on execution time and I don't want them to be influenced by other stuff running. My problem is that once the first command has finished producing its output, the second command should keep on going (for quite a long time), but control returns to the shell and that command continues in background.

The script does something like:

java path.to.script param1 >(path/to/other/script param2 param3)
java path.to.script param4 >(path/to/other/script param5 param6)

but as soon as the java command in the first line has completed it goes straight to the next line, resulting in the path/to/other/script being executed twice at the same time.

To be more clear, I want the prompt to appear only after the whole first command line has finished, that is after path/to/other/script has finished its job.

How do I do that?


Solution

  • A process substitution will indeed continue to run in the background, outside of the calling shell's control. You probably simply want

    java path.to.script param1 | path/to/other/script param2 param3
    java path.to.script param4 | path/to/other/script param5 param6