python print statement adds new line and 0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • josh wold
    New Member
    • Nov 2010
    • 1

    python print statement adds new line and 0

    Here is my problem. I'm using plink to ssh to devices and pull info off. I need to manipulate this data so that extra 0 at the end is making it difficult.


    C:\Python30>pyt hon PLINKSSHtest.py
    Enter your username: josh
    Password:
    plink -pw nowayjose -ssh nope@1.1.1.1 "show run | inc hostname"
    hostname net-R2
    0 <------------MY ISSUE

    C:\Python30>pli nk -pw nowayjose -ssh nope@1.1.1.1 "show run | inc hostname"
    hostname net-R2
    <------------WHAT I EXPECT
    C:\Python30>

    Here's the code (very simple code):

    Code:
    def read_dev():
    	# Print statement here for debugging
    	print ("plink -pw " + password + " -ssh " + user + "@" + HOST + " " + command)
    	cur_dev = os.system("plink -pw " + password + " -ssh " + user + "@" + HOST + " " + command)
    	return(cur_dev)
    
    HOST = None
    user = input("Enter your username: ")
    password = getpass.getpass()
    command = '"show run | inc hostname"'
    HOST = '1.1.1.1'	
    print (read_dev())
    I'm a n00b so the more english you can use the better -.o

    Thanks in advance!!
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    This statement
    print (read_dev())
    prints the return from os.system, which is apparently a zero, and depends on the OS Python is on. Instead, try
    cur_ret = read_dev()
    and you can always print cur_ret if you want to know what was returned by os.system

    Comment

    Working...