Background
As a fun project, I have decided to create a remote control application for my new Raspberry Pi. I know how to use SSH, but I wanted to implement somthing similar in Python. How can I get the text that is printed out onto the terminal to display in my Python shell?
I checked out this SO question, but it did not work. By did not work, I mean that I am not able to see the output text. If I enter passwd
, it gives me only
Changing password for User.
But it does not give me the interactive session. THAT is what I am trying to figure out.
NOTE: my Raspberry Pi is running on “Wheezy.” Also, it would be great if this program could work with other operating systems (such as Windows 7, Mac OS X).
Code
import subprocess
import socket
import sys
import platform
import os
print "WELCOME TO xTROL. \n"
pyVER = sys.version
OS = platform.system()
print pyVER, "\n"
print "Running on %s" % (OS)
while True:
INPUT = raw_input(">>>")
cmd_FORMAT = INPUT.split()
try:
output = subprocess.Popen(cmd_FORMAT, stdout=subprocess.PIPE).communicate()[0]
print output
except Exception:
print "Something went wrong."