[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: exec 0<.... question
From: |
#!microsuxx |
Subject: |
Re: exec 0<.... question |
Date: |
Wed, 30 Oct 2024 03:46:22 +0100 |
aha , so
exec'ing 0<fifo forces it into the shell overall env , for first for the
shell second for cmds
its nearly my case
i think for my case i just need to
save 0 before and reuse it later
my case is :
i make ollama wrapper
for short cmds , functions , and logging all to partly individual files
i had made some tests and have a previous version
ollama is ai app , dl run models , text inside , get answers
the current problem with prev version is that
control-c's in not-all situations make it quit , instead of in its app
return to editfield screen
i observed thi prollu relating to tee usage
tee -a ... < <( cmds ; ollama ; ... )
now i try to make fifos
make a reader , for them , that duplicates to log files and terminal
then spawn ollama , and use redir system to look ollamas reaction
ah yea some input duplicattion system i need too
greets !!
On Wed, Oct 30, 2024, 03:35 Greg Wooledge <greg@wooledge.org> wrote:
> On Wed, Oct 30, 2024 at 03:22:47 +0100, #!microsuxx wrote:
> > if i exec 0 like from a fifo , exec without cmd
> > can i type then into the bash cmdline and it appears rather into the fifo
> > or , does it apply just on next cmd
>
> File descriptor 0 is standard input. If you do "exec 0<somefifo" you
> will close stdin (which was previously reading from your terminal) and
> instead try to read from your FIFO.
>
> The exec call will block until the FIFO has *also* been opened for writing
> by some other process.
>
> Once the exec call finishes, the FIFO has been opened twice by two
> different processes, and your shell is ready to read input from the
> FIFO.
>
> It will not read input from your terminal any longer.
>
> If you want to play around with this, open two terminal windows, and then:
>
> 1. In window 1, create a FIFO (e.g. mkfifo p).
> 2. In window 1, do "exec 0<p". This will hang.
> 3. In window 2, do "exec 1>p". This should un-hang window 1.
> 4. In window 2, type a simple command, like "echo date".
> The *output* of your command will be written to the FIFO, and read
> as input by the shell in window 1.
> 5. In window 1, type whatever you want, and observe that it is ignored.
> 6. In window 2, exit from the shell. Window 1 will also be closed.
> 7. Don't forget to clean up your FIFO.
>
>