Home Man
Today's Posts

Python: Redirecting to tty and reading from tty

Shell Programming and Scripting

Kindly Note - This is a Single User Post by Forum Member SkySmart Regarding:
Python: Redirecting to tty and reading from tty.
Please Follow The Primary Link Above to View the Full Discussion.

Old 05-16-2018
Python: Redirecting to tty and reading from tty

In bash, you can do something like this:

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:


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:

cat bashscript.sh | bash

Whereas the python script doesnt work when run like this:

cat pythonscript.py | python

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

All times are GMT -4. The time now is 05:12 PM.
Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.