I managed to get it working!
I just added let tempin = Unix.dup Unix.stdin in
at the beginning of exec_pipeline before my loop, and Unix.dup2 tempin Unix.stdin;
as the second to last line, right before !lastexitcode
.
Seems that all I needed to do was save the file descriptor somewhere and restore it. Not sure if this is the optimal solution (open to suggestions of course!) but it works.
@nojb Thank you so much for the tip!