Fix hang after executing extern commands in a row

Thanks to filterfalse.
Merge branch 'fix-terminal-hang'