tags:

views:

134

answers:

3

Hi,

Bit support question. Apologies for that. I have an application linked with GNU readline. The application can invoke shell commands (similar to invoking tclsh using readline wrapper). When I try to invoke the Linux less command, I get the following error: Suspend (tty output)

I'm not an expert around issues of terminals. I've tried to google it but found no answer. Does any one know how to solve this issue?

Thanks.

A: 

Whilst counterintuitive it may be stopped waiting for input (some OSs and shells give Stopped/Suspended (tty output) when you might expect it to refer to (tty input)). This would fit the usual behaviour of less when it stops at the end of (what it thinks is) the screen length.

Can you use cat or head instead? or feed less some input? or look at the less man/info pages to see what options to less might suit your requirement (e.g w, z, F)?

mas
A: 

Your readline application is making itself the controlling app for your tty.
When you invoke less from inside the application, it wants to be in control of the tty as well.

If you are trying to invoke less in your application to display a file for the user, you want to set the new fork'd process into it's own process group before calling exec.
You can do this with setsid(). Then when less call tcsetpgrpp(), it will not get thrown into the backgroud with SIGTTOU.

When less finishes, you'll want to restore the foregroud process group with tcsetpgrp(), as well.

codeDr
+1  A: 

You probably need to investigate the functions rl_prep_terminal() and rl_deprep_terminal() documented in the readline manual:

Function: void rl_prep_terminal(int meta_flag)

Modify the terminal settings for Readline's use, so readline() can read a single character at a time from the keyboard. The meta_flag argument should be non-zero if Readline should read eight-bit input.

Function: void rl_deprep_terminal(void)

Undo the effects of rl_prep_terminal(), leaving the terminal in the state in which it was before the most recent call to rl_prep_terminal().

The less program is likely to get confused if the terminal is already in the special mode used by the Readline library and it tries to tweak the terminal into an equivalent mode. This is a common problem for programs that work with the curses library, or other similar libraries that adjust the terminal status and run other programs that also do that.

Jonathan Leffler