How to set stty row and columns of the terminal through C program


 
Thread Tools Search this Thread
Top Forums Programming How to set stty row and columns of the terminal through C program
# 1  
Old 02-06-2009
How to set stty row and columns of the terminal through C program

Hi,

I'm have a big problem with one of the C programs that I'm developping.
actually, I'm trying to monitor the users' session in solaris.
therefore, I have used the source code of the unix "script" command. but the problem is that, when i run that program, the stty settings are lost:
speed 38400 baud; -parity
erase = ^h; swtch = <undef>;
brkint -inpck -istrip icrnl -ixany imaxbel onlcr tab3
echo echoe echok echoctl echoke iexten
However, before executing it, it was like this:
speed 38400 baud; -parity
rows = 50; columns = 132; ypixels = 0; xpixels = 0;
erase = ^h; swtch = <undef>;
brkint -inpck -istrip icrnl -ixany imaxbel onlcr tab3
echo echoe echok echoctl echoke iexten

This is actually resulting in having problems while trying to edit any file with VI editor or view it with the "less" command...
so, can anyone help me on how to get set the rows and columns size from inside the C program?
thank you in advance.
Regards,
Saad
# 2  
Old 02-06-2009
First off, once you use script, is the resulting environment even still a terminal?
# 3  
Old 02-08-2009
Check

Hi Corona688,

When I execute the script, I see that new terminal is set.
root@voms11 # tty
/dev/pts/2
root@voms11 # ./script
root@voms11 # tty
/dev/pts/4

by the way, I have attached the script I'm using. so, if you can tell me how can i exactly set the rows/columns options in that terminal.

thank you.
# 4  
Old 02-09-2009
You can save your tty's values with stty -g, then restore them by giving stty that same output on the commandline. How to do this in C is a trickier question if you don't feel like using system(), since there's a lot of ioctl calls involved. You could run strace on stty to see what calls its making to get the values and set the values, though sometimes it might print ambiguous statements due to ioctls meaning different things on different kinds of files.
# 5  
Old 02-10-2009
Thanks

Hi Corona688,

Thanks for your precious help.
However, I could mange monitoring of user sessions using the screen tool, it is much more sophisticated that the script tool Smilie.

thanks again for your help.
Regards,
Saad
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use stty columns 140 in .profile on ksh

Hi, I am trying to put stty columns 140 in .profile to set column width to 140 so I don't have to manully do it every time. My main goal is to avoid seeing "Terminal too wide" message whenever I try to use vi editor in full screen. I am on korn shell echo $SHELL /bin/ksh So even... (8 Replies)
Discussion started by: pat_pramod
8 Replies

2. UNIX for Dummies Questions & Answers

STTY Columns Setting Environment Variable?

I am wondering about the following: stty columns 140 I have found that a number of times I need to set my display columns to a high number (such as 140) but I have to do this every time I login to use putty/ssh. Can we set this with an environmental variable so that it is permanent? Also... (4 Replies)
Discussion started by: newbie2010
4 Replies

3. Linux

Gnuplot terminal set to 'unknown'

I installed version 4.6.4 of gnuplot recently on my system running 10.04 ubuntu linux. I am getting error Terminal type set to 'unknown' Also when i try to set term X11 or wxt i get error Terminal type set to 'unknown' ^ unknown or ambiguous terminal... (5 Replies)
Discussion started by: Ujjwal1982
5 Replies

4. UNIX for Dummies Questions & Answers

Select 2 columns and transpose row by row

Hi, I have a tab-delimited file as follows: 1 1 2 2 3 3 4 4 a a b b c c d d 5 5 6 6 7 7 8 8 e e f f g g h h 9 9 10 10 11 11 12 12 i i j j k k l l 13 13 14 14 15 15 16 16 m m n n o o p p The output I need is: 1 1 a a 5 5 e e 9 9 i i 13... (5 Replies)
Discussion started by: mvaishnav
5 Replies

5. UNIX for Dummies Questions & Answers

help [[row and columns]]

i ask to do ,,program that convert the last row to be the first row ,,,and after that exchange the the columns ex,, 1 2 3 4 5 6 7 8 9 to be 7 8 9 4 5 6 1 2 3 and then to be 9 8 7 6 5 4 3 2 1 (0 Replies)
Discussion started by: khaled1989kh
0 Replies

6. Shell Programming and Scripting

help [[row and columns]]

i ask to do ,,program that convert the last row to be the first row ,,,and after that exchange the the columns ex,, 1 2 3 4 5 6 7 8 9 to be 7 8 9 4 5 6 1 2 3 and then to be 9 8 7 6 5 4 3 2 1 give mee the code .... (0 Replies)
Discussion started by: khaled1989kh
0 Replies

7. Linux

Serial terminal emulation - bad row column count ?

Hello, I connect to linux using serial cable from windows machine. I use putty as serial terminal emulator. Everything works fine except programs which scroll text - man, more, less, vi, etc.. These programs asumme my terminal size is 80cols x 24rows (my putty window size is more than that,... (1 Reply)
Discussion started by: vilius
1 Replies

8. Shell Programming and Scripting

how to set background color in Unix terminal

Hi All, how do I set in .profile file Unix terminal background color = BLUE ? Please advice me. :confused: (2 Replies)
Discussion started by: raghur77
2 Replies

9. Programming

Send email for each row in a result set

I have SQL giving me output of disabled ids in the system every day. I can send on email for this disabled user list. But I want to send one email for every disabled user or for every row. thank you for your help. Kyle (2 Replies)
Discussion started by: s1a2m3
2 Replies

10. UNIX for Dummies Questions & Answers

Row to Columns

Hi, I have a file like this. 1,1,1,0,0,0 1,1,2,1,0,0 1,1,3,0,0,0 1,1,4,0,0,0 ........... ........... 1,1,24,0,0,0 1,1,25,0,0,0 1,1,26,1,0,0 1,1,27,0,0,0 1,2,1,0,0,0 1,2,2,0,0,0 1,2,3,0,0,0 1,2,4,0,0,0 1,2,5,1,0,0 1,2,6,1,0,0 (4 Replies)
Discussion started by: vskr72
4 Replies
Login or Register to Ask a Question