The timeout command itself has a --foreground
option. This lets the command interact with the user "when not running timeout directly from a shell prompt".
timeout --foreground the_command its_options
I think the questioner must have been aware of the very obvious solution of the timeout
command, but asked for an alternate solution for this reason. timeout
did not work for me when I called it using popen
, i.e. 'not directly from the shell'. However, let me not assume that this may have been the reason in the questioner's case. Take a look at its man page.