Sponsored Content
Top Forums Shell Programming and Scripting Python: Redirecting to tty and reading from tty Post 303017435 by SkySmart on Wednesday 16th of May 2018 02:03:55 AM
Old 05-16-2018
Python: Redirecting to tty and reading from tty

In bash, you can do something like this:

Code:
#!/bin/bash
echo -n "What is your name? " > /dev/tty
read thename < /dev/tty

How can I do the same in python?

I have a python script that has the following content:

Code:
#!/usr/bin/python2.7

import getpass
import sys
import telnetlib
import time
print ""
uip = raw_input("Enter your IP Address: ")
print ""
uname = raw_input("Enter your username: ")
print ""
upass = getpass.getpass("Enter your password: ")
tn = telnetlib.Telnet(uip)
print ""
print "Successfully Connected to", uip
print ""

The bash script works even when it is run through a pipe as in:

Code:
cat bashscript.sh | bash

Whereas the python script doesnt work when run like this:

Code:
cat pythonscript.py | python

I need to be able to read from tty when running a script through a pipe.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help on processes not associated with a TTY

Hi all ^_^ Okay, here's the problem: There's an IBM RS6000 server running AIX 4.3 with Informix database in my workplace. During peak hours, it has about 350 users doing mostly database operations. It has been set up that those users can only log-in the system at one terminal at a time. Due... (3 Replies)
Discussion started by: bluefactory
3 Replies

2. Programming

TTY programming

Hi gurus, Need help to code some tools dealing with all the tty thingies, raw mode etc .... Can you juss point me to some cool links related to tty programming, i've tried google but found none so far :confused: Thanks all. (2 Replies)
Discussion started by: andryk
2 Replies

3. UNIX for Dummies Questions & Answers

tty problem

Dear all, when I do a remote shell command from a FUJITSU Unix to an HP-UX, I always get this: 15:36:35 + rsh -l storto obs2 sh /users/obs/storto/MESO-NH/tmp_olive_map_00CC/job_prepex_70JY_C00CC_20041103_19 Not a terminal stty: : Erreur inconnue stty: : Erreur inconnue... (0 Replies)
Discussion started by: stortignauz
0 Replies

4. UNIX for Dummies Questions & Answers

tty remote IP

I am fairly new to Unix Terminal outputs and I have a server that is sending print jobs to a PortServer 8 RJ45 situated in a remote location. It is working fine however we need to change the Subnet of that location and I am unable to find where the IP associated with the terminal is located. ... (4 Replies)
Discussion started by: martin_Montreal
4 Replies

5. AIX

tty

Hi All can anyone tell me what is the meaning of tty,or give me an example of this? (1 Reply)
Discussion started by: magasem
1 Replies

6. UNIX for Dummies Questions & Answers

pts and tty

hi iam very new to linux can anyone tell me about pts and tty acctually today morning i logged into my pc at 9:51 when i have given #who it has given sam tty7 9:51 sam pts/1 10:11 so what does it mean (1 Reply)
Discussion started by: praneel2k
1 Replies

7. UNIX for Dummies Questions & Answers

What does this TTY info mean?

When I do a who command I get the following: mohit :0 2009-04-07 14:07 mohit pts/0 2009-04-07 17:25 (:0.0) mohit pts/1 2009-04-09 12:07 (:0.0) mohit pts/2 2009-04-16 11:38 (:0.0) mohit pts/3 2009-04-16 16:09 (:0.0) mohit pts/4 ... (1 Reply)
Discussion started by: mojoman
1 Replies

8. UNIX for Dummies Questions & Answers

TTY Insane

Hi All, Long time reader, first time poster. I have a tip session to a v480 serial console running Solaris 9. Look at this mess I'm getting back... connected... (16 Replies)
Discussion started by: danny.hudson
16 Replies

9. UNIX for Advanced & Expert Users

tty changes?

I am not sure if I am using the correct terminology but somehow my tty keeps changing on me. The man pages are confusing to me on what exactly the tty is. This is what I see when I run the tty command. Could anyone explain why my tty keeps changing? ~ $ tty /dev/pts/1 ~ $ tty /dev/pts/0 (6 Replies)
Discussion started by: cokedude
6 Replies

10. UNIX for Dummies Questions & Answers

Reading password from /dev/tty

hi, From the below script: ##########################################pwd_auth.sh######################################################################################## #Author: Pandeeswaran Bhoopathy #Written on:26th Jan 2012 2:00PM #This script describes the feature of stty and illustrates... (3 Replies)
Discussion started by: pandeesh
3 Replies
TTYSNOOP(8)						    BSD System Manager's Manual 					       TTYSNOOP(8)

NAME
ttysnoop -- snoop on a user's tty SYNOPSIS
ttysnoop [pty] ttysnoops DESCRIPTION
The ttysnoop / ttysnoops client-server combo can be used to snoop (watch) on a user's login tty. The server (ttysnoops) is usually started by getty(8) or telnetd(8) and reads the file /etc/snooptab to find out which tty's should be cloned and which programs to run on them (usu- ally /bin/login). A tty may be snooped through a pre-determined (ie. fixed) device, or through a dynamically allocated pseudo-tty (pty). This is also specified in the /etc/snooptab file. To connect to the pty, the client ttysnoop should be used. The available pseudo terminals pty are present as sockets in the directory /var/spool/ttysnoop/. Format of /etc/snooptab The /etc/snooptab file may contain comment lines (starting with a '#'), empty lines, or entries for tty's that should be snooped upon. The format of such an entry is as follows: tty snoop-device type program where tty is the leaf-name of the tty that should be snooped upon (eg. ttyS2, not /dev/ttyS2) OR the wildcard '*', which matches ANY tty. snoop-device is the device through which tty should be snooped (eg. /dev/tty8) OR the literal constant "socket". The latter is used to tell ttysnoops that the snoop-device will be a dynamically allocated pty. type specifies the type of program that should be run, currently recog- nized types are "init", "user" and "login" although the former two aren't really needed. Finally, program is the full pathname to the program to run when ttysnoops has cloned tty onto snoop-device. EXAMPLE
The following example /etc/snooptab file should illustrate the typical use of ttysnoop / ttysnoops: # # example /etc/snooptab # ttyS0 /dev/tty7 login /bin/login ttyS1 /dev/tty8 login /bin/login # # the wildcard tty should always be the last one in the file # * socket login /bin/login # # example end # With the above example, whenever a user logs in on /dev/ttyS0 or /dev/ttyS1, either tty will be snooped through /dev/tty7 or /dev/tty8 respectively. Any other tty's will be snooped through a pty that will be allocated at the time of login. The system-administrator can then run ttysnoop pty to snoop through the pty. Note that it is up to the system-administrator to setup getty and/or telnetd so that they execute ttysnoops instead of /bin/login. SEE ALSO
getty(8), telnetd(8) FILES
/etc/snooptab BUGS
The program is unable to do any terminal control-code translations for the original tty and the snoop-device. I doubt it will ever do this. AUTHOR
Carl Declerck, carl@miskatonic.inbe.net BSD
August 8 1994 BSD
All times are GMT -4. The time now is 12:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy