help-bash
[Top][All Lists]
Advanced

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

Re: How to force delay in command execution in unamed pipe?


From: Peng Yu
Subject: Re: How to force delay in command execution in unamed pipe?
Date: Sun, 3 Apr 2022 07:18:10 -0500

On Sun, Apr 3, 2022 at 1:54 AM Andreas Kusalananda Kähäri <
andreas.kahari@abc.se> wrote:

> On Sun, Apr 03, 2022 at 12:11:37AM -0500, Peng Yu wrote:
> > Hi
> >
> > cmd <(cmd1) <(cmd2)
> >
> > For a command like the above, I will need to let cmd2 run after cmd1
> > finishes. Of course, one could use temp files like the following. But
> > is there a way to follow such a constraint with unnamed pipes?
> >
> > cmd1 > file1
> > cmd2 > file2
> > cmd file1 file2
> >
> > Another way to avoid using unnamed pipes is to use a pipeline with
> > redirection like this. Is there a way to force cmd2 to run only after
> > cmd1 finishes in this pattern?
> >
> > cmd1 | {
> > cmd2 | {
> > cmd "$fd1" "$fd2"
> > } {fd2}<&0
> > } {fd1}<&0
> >
> > --
> > Regards,
> > Peng
>
> Please say more about what "cmd1", "cmd2", and "cmd" do, and especially
> in what order "cmd" is consuming data from the files mentioned on its
> command line.


You should not assume anything in this aspect.

If "cmd1" needs to deposit its complete output somewhere
> before "cmd2" is allowed to run, then
>
> * "cmd1" is only allowed to write a small enough amount of data as to
> not fill the pipe buffer, or


The data is small enough to be held in the buffer.

>
>
> * "cmd1" needs to write to a file, or


cmd1 prints to stdout.


>
> * "cmd" needs to consume the output from "cmd1" before reading the data
> from "cmd2" (this would incidentally also mean "cmd2" would block until
> "cmd1" finishes, which in a sense solves your issue,


It doesn’t. The program of cmd2 should not start before cmd1 finishes. In
the case that you mentioned, cmd2 could start it is just its writing output
is halted by cmd, which is irrelevant to my question.

depending on the
> amount of data "cmd2" produces and whether you're piping or redirecting
> the outputs, and whether you mean "start" when you say "run" or not.)


The data is small enough so the blocking scenario that you mentioned should
not be considered.

For this question, the only concern is how to delay commands running in
unnamed pipes.

>
>
>
> --
> Andreas (Kusalananda) Kähäri
> SciLifeLab, NBIS, ICM
> Uppsala University, Sweden
>
> .
>
-- 
Regards,
Peng


reply via email to

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