Let us say I have .c file and corresponding executable (let us say foo) that takes in some input from stdin and then makes a sys call to /bin/sh. Feeding input to this executable like following:python -c <some script to feed input> | ./fooI observed that the shell invoked by foo closes immediately and foo terminates. However, someone on IRC recommended that executing like this:(python -c <some script to feed input>; cat) | ./fookeeps the subshell invoked by ./foo still running. I would like to know what is going on here. My Speculation: For the first case, Does the stdout of the python script close as soon as it's done thus sending EOF to the stdin of the process ./foo terminating ./foo? But that does not make sense to me as the sys call should be a blocking one leading to ./foo not terminating. I would appreciate help and a pointer to resources to fix erroneous understanding. Thanks!
Understanding behavior of subshell and stdout with pipe
shell;pipe;subshell