Use tty or pipe depending on type