output to terminal


 
Thread Tools Search this Thread
Top Forums Programming output to terminal
# 1  
Old 10-13-2003
output to terminal

How can I write to another user's pseudo tty, but not to its current prompt position (as in open("/dev/pts007", ...) followed by write() ). Instead I would like to write to the top center of the screen using color red, for example. Like curses, but from another console.
# 2  
Old 10-13-2003
There is no way to do that without encountering unsolvable problems.

If you have write permission, you can spit out a sequence of characters and hope for the best. wall does that and the message is sometimes garbled.

You can ask the user to shutdown his program and run a program that you wrote instead. This program can read his environment and learn how to configure his terminal. talk does that and it works fairly well.

And not all terminals can display red characters.
# 3  
Old 10-14-2003
Thank you for your reply
I'm asking because I've seen something along these lines done. The program is writing warnings each minute for a period of time to all the consoles that are running a specific process. From the list of procs it obtains a list of pts. The sending is multithreaded and sincronized by semaphores. I do not know how it actually writes to the other consoles. With nm I get:
...
|FUNC |GLOB |0 |8 |warnuser
|FUNC |GLOB |0 |UNDEF |close
|FUNC |GLOB |0 |UNDEF |strcat
|OBJT |GLOB |0 |ABS |_edata
|FUNC |GLOB |0 |UNDEF |write
|FUNC |GLOB |0 |UNDEF |sleep
|FUNC |GLOB |0 |UNDEF |sema_wait
|FUNC |GLOB |0 |UNDEF |atexit
|FUNC |GLOB |0 |8 |main
|FUNC |GLOB |0 |UNDEF |fputs
|FUNC |GLOB |0 |UNDEF |fgets
|OBJT |GLOB |0 |9 |_lib_version
|OBJT |GLOB |0 |17 |___Argv
|FUNC |GLOB |0 |UNDEF |strlen
|FUNC |GLOB |0 |UNDEF |_cleanup
|FUNC |GLOB |0 |8 |_start
|FUNC |GLOB |0 |UNDEF |strtok
|FUNC |GLOB |0 |UNDEF |thr_create
|OBJT |GLOB |0 |ABS |_etext
|FUNC |GLOB |0 |UNDEF |sprintf
|FUNC |GLOB |0 |UNDEF |open
|FUNC |GLOB |0 |11 |_init
|OBJT |WEAK |0 |14 |environ
|OBJT |GLOB |0 |14 |thr_sync
|FUNC |GLOB |0 |UNDEF |exit
|OBJT |GLOB |0 |ABS |_DYNAMIC
|OBJT |GLOB |0 |ABS |_end
|FUNC |GLOB |0 |12 |_fini
|FUNC |GLOB |0 |UNDEF |fclose
|OBJT |GLOB |0 |UNDEF |errno
|FUNC |GLOB |0 |UNDEF |__fpstart
|FUNC |GLOB |0 |UNDEF |fopen
|FUNC |GLOB |0 |UNDEF |sema_post
|FUNC |GLOB |0 |UNDEF |system
|OBJT |GLOB |0 |ABS |_GLOBAL_OFFSET_TABLE_
|OBJT |GLOB |0 |14 |_environ
# 4  
Old 10-14-2003
It sounds like it is contacting that specific process and requesting that a message be displayed. That is similiar to the talk model. Since you're on SunOS, you can use truss to see exactly what it is doing.
# 5  
Old 10-15-2003
Actually it's OpenUnix Caldera but truss works just the same.
Here is the interesting part:
Code:
12562:  open("/dev/pts/8", O_WRONLY, 0)                 = 4               
12562:  sigprocmask(SIG_SETMASK, 0xA7F6C2A0, 0x00000000) = 0              
12562:  write(4, 0xA7F4693C, 39)                        = 39              
12562:    1B [ s1B [ 1 ; 3 8 H1B [ 3 1 ; 1 m Y o u   s t i l l   h a v e   
12562:     5 m i n1B [ u

So I guess these are control sequences at the beginning/end. Are they hex? There is a special .tinfo file but the entries are of the type:
...
kf2=\E[N, kf3=\E[O
...

Last edited by Yogesh Sawant; 05-26-2010 at 03:07 AM.. Reason: added code tags
# 6  
Old 10-15-2003
When truss is displaying a string, it will display the character if it is printable and it puts a space between the letters. If the character is not printable is outputs in hex and in this case it will need two positions, so you lose the space.

1B is an escape character. You can see it (maybe) with "man ascii". Octal is a little more common in the unix world. You can convert hex to octal via bc. Quick example:
echo "obase=8;ibase=16;1B" | bc

Those are usually called escape sequences. Once you know that an escape is 33 in octal, you can model this in ksh:
Code:
#! /usr/bin/ksh
print -n '\033[s\033[1;38H\033[31;1mYou still have 5 min\033[u
sleep 5
exit 0

The sleep will delay the printing of your prompt long enough to see what happened. The first and last escape sequences are mysteries to me. The second moves the cursor. The third is an sgr (select graphic rendition) The 1 goes to bold mode. I have no idea what the 31 is supposed to do. It is a nop with my xterm. And this leaves my terminal in bold mode. I had to do a "tput sgr0" to fix it.

But if I was using hpterm instead of xterm, this would not work at all. That is the problem with this sort of thing, you must guess at the user's terminal.

Last edited by Yogesh Sawant; 05-26-2010 at 03:08 AM.. Reason: added code tags
# 7  
Old 10-16-2003
Thanks,
I think they are:
1B [ s sc to save cursor
1B [ 1 ; 3 8 H cup to position cursor
1B [ 3 1 ; 1 m changes color to red
1B [ u rc to restore cursor
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print Terminal Output Exactly how it Appears in the Terminal to a New Text File

Hello All, I have a text file containing output from a command that contains lots of escape/control characters that when viewed using vi or view, looks like jibberish. But when viewed using the cat command the output is formatted properly. Is there any way to take the output from the cat... (7 Replies)
Discussion started by: mrm5102
7 Replies

2. Shell Programming and Scripting

All output to terminal pager by default

How can I have all my output to a terminal pager by default. I want all output to pause once screen is full. Piping to more does not work if the app/script is interactive (2 Replies)
Discussion started by: aydj
2 Replies

3. Shell Programming and Scripting

Redirect output from terminal

i make a shell script. There has a line wget https://cisofy.com/files/lynis-2.1.0-88394c1affb9e23bd7390098947b3fd4b04e35e8.tar.gzWhen this line execute terminal show some text like this Resolving cisofy.com (cisofy.com)... 149.*.*.* Connecting to cisofy.com (cisofy.com)|149.*.*.*|:4444...... (4 Replies)
Discussion started by: Devils-ey3
4 Replies

4. Shell Programming and Scripting

Redirecting script output to terminal

When ever i started my terminal,Every time I have to change the directory like "cd user/documents/ravi/folder2/folder3" Without typing this entire command every time ,I placed "alias c='cd user/documents/ravi/folder2/folder3'" in .bash_profile file. so that i can able to execute command 'c'... (6 Replies)
Discussion started by: Raviteja saddal
6 Replies

5. Shell Programming and Scripting

Truncate terminal output

Hello Using BASH under Ubuntu 10.4 lts + XMonad My script is almost perfect but i'm stuck at the last hurdle: I need a sort of modified 'echo' which truncates its output to the width of the terminal I can find the terminal's width with 'stty size' but i dont know how to then convert input... (2 Replies)
Discussion started by: scyptnex
2 Replies

6. Shell Programming and Scripting

How can I scroll the terminal output with Expect

Hi, I'm trying to come up with a simple expect script that allows me to login to a system and run a single command ... something like this: #!/usr/bin/expect -f # let's set some variables #set password set ipaddr set ponumber set hostname set timeout -1 # let's now connect to the... (0 Replies)
Discussion started by: danielsf
0 Replies

7. UNIX for Advanced & Expert Users

Terminal Output to a File ??

Hey, How can I transfer the terminal output to a file ? For example : command "fuser" returns the "process-id" and prints the output on the terminal, but I want that output to a file as well. How can I do that ? /clocal/mqbrkrs/user/mqsiadm/sanjay/AccessMonitor $ fuser -uf... (2 Replies)
Discussion started by: varungupta
2 Replies

8. Solaris

how to redirect my output in a new terminal

Hi all, i type a command along with dtterm what i would like to have is that the output of the command to be shown in the new terminal . Any Idea on how to acheive this? (0 Replies)
Discussion started by: Sayantan
0 Replies

9. Solaris

terminal output - save to file?

I have a window open on my ultra 10 - a terminal window connecting to a server. Is there any way I can log all output to this window to a log file on my ultra 10 ? (2 Replies)
Discussion started by: frustrated1
2 Replies

10. UNIX for Dummies Questions & Answers

Output to terminal and file at the same time

Hi all The makefile of a large project produces hundreds of lines of output, which I can't look at any more when the build is finished. If I simply redirect the output to a file, I can't see the progress of the building process... Is there a possibility to redirect the output to a file and at... (1 Reply)
Discussion started by: Charlie
1 Replies
Login or Register to Ask a Question