help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Waiting for a sub-process to finish


From: Greg Wooledge
Subject: Re: [Help-bash] Waiting for a sub-process to finish
Date: Thu, 1 Jun 2017 16:27:35 -0400
User-agent: Mutt/1.4.2.3i

On Thu, Jun 01, 2017 at 10:11:04PM +0200, João Eiras wrote:
>   long_command -o >(gzip -c > file.gz)

> This happens because the subprocess ">(gzip -c > file.gz)" has not had time
> to finish and close the output file.
> 
> Question: How can I force bash to wait until all subprocesses to finish ?
> 
> 'wait' does not work here as these are not background tasks managed by the
> job control.

The most portable answer would be to create your own named pipe, and run
the long_command in the background and the gzip in the foreground:

mkfifo mypipe
long_command -o mypipe &
gzip -c <mypipe >file.gz
wait

(You could also run gzip in the background and let wait wait for it,
but there doesn't seem to be any real gain there.)

Other than that, bash 4.4 added this new feature:

u.  Bash now allows waiting for the most recent process substitution, since it
    appears as $!.

I believe you have to explicitly pass the PID to wait for those, rather
than just calling wait with 0 arguments, but it's not something I've
played with much.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]