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
STARTSRV(8)						      System Manager's Manual						       STARTSRV(8)

NAME
startsrv - invoke ttysrv for a particular host. SYNOPSIS
startsrv host DESCRIPTION
startsrv fires up ttysrv for a given host. It will kill any already running instance for that host, then read /etc/remote- tty/opt/<host>.srv for any options to pass to ttysrv (defaulting to those that set 9600,8n1), /etc/remote-tty/prot/<host>.sock for the per- missions the socket should be set to (default 660), /etc/remote-tty/owner/<host>.sock for the owner of the socket (default rttymgr:dialout) and /etc/remote-tty/prot/<host>.log for the permissions of the logfile (default 640). The device node used is /etc/remote-tty/dev/<host>. This will normally be a symlink to the correct file in /dev. ttysrv is configured to log to /var/log/remote-tty/<host>/<host>, with a pidfile at /var/run/remote-tty/pid/<host> and the socket at /var/run/remote-tty/sock/<host>. SEE ALSO
remote-tty(1), ttysrv(8). AUTHOR
rtty was written by Paul Vixie <vixie@isc.org>. This manual page was written by Jonathan McDowell <noodles@earth.li> for the Debian project (but may be used by others). May 23, 2006 STARTSRV(8)
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy