Python: Redirecting to tty and reading from tty

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
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.
# 2  
Old 05-16-2018
Hi...

I am missing something, why do you need a python script to be piped into python?
You are already calling python in your shebang...
Longhand OSX 10.13.4, default bash terminal.
Code:
Last login: Wed May 16 17:56:35 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Python
AMIGA:barrywalker~/Desktop/Code/Python> chmod 755 test.py
AMIGA:barrywalker~/Desktop/Code/Python> cat test.py
#!/usr/bin/python
import sys
print("This is a test line.")
text = raw_input("Enter your name: ")
print(text)
sys.exit()
AMIGA:barrywalker~/Desktop/Code/Python> ./test.py
This is a test line.
Enter your name: My name is Bazza...
My name is Bazza...
AMIGA:barrywalker~/Desktop/Code/Python> _

# 3  
Old 05-16-2018
Quote:
Originally Posted by wisecracker
I am missing something, why do you need a python script to be piped into python?
Security through obscurity. Skysmart runs programs through a long train of generators and mutators in the theory that this will prevent people from wanting to use it anywhere else.
This User Gave Thanks to Corona688 For This Post:
wisecracker (05-16-2018)
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading password from /dev/tty pandeesh UNIX for Dummies Questions & Answers 3 01-30-2012 05:13 PM
tty changes? cokedude UNIX for Advanced & Expert Users 6 11-11-2010 06:39 AM
tty hack xxmasrawy Solaris 1 10-11-2010 02:44 PM
Killing the tty thmnetwork Linux 2 11-02-2009 10:39 PM
TTY Insane danny.hudson UNIX for Dummies Questions & Answers 16 09-08-2009 03:21 PM
What does this TTY info mean? mojoman UNIX for Dummies Questions & Answers 1 04-18-2009 06:36 AM
pts and tty praneel2k UNIX for Dummies Questions & Answers 1 06-05-2008 05:28 AM
Tty Over Run TheEngineer AIX 0 05-30-2007 03:48 AM
tty magasem AIX 1 11-28-2006 03:58 AM
tty remote IP martin_Montreal UNIX for Dummies Questions & Answers 4 03-01-2006 05:31 PM
tty problem stortignauz UNIX for Dummies Questions & Answers 0 06-06-2005 04:54 AM
TTY programming andryk Programming 2 05-30-2005 03:43 AM
kill the tty vascobrito Shell Programming and Scripting 9 04-09-2004 12:06 PM
Help on processes not associated with a TTY bluefactory UNIX for Dummies Questions & Answers 3 10-15-2001 09:48 AM
All times are GMT -4. The time now is 12:52 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.