By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

python print statement adds new line and 0

P: 1
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>python 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>plink -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):

Expand|Select|Wrap|Line Numbers
  1. def read_dev():
  2.     # Print statement here for debugging
  3.     print ("plink -pw " + password + " -ssh " + user + "@" + HOST + " " + command)
  4.     cur_dev = os.system("plink -pw " + password + " -ssh " + user + "@" + HOST + " " + command)
  5.     return(cur_dev)
  6.  
  7. HOST = None
  8. user = input("Enter your username: ")
  9. password = getpass.getpass()
  10. command = '"show run | inc hostname"'
  11. HOST = '1.1.1.1'    
  12. print (read_dev())
I'm a n00b so the more english you can use the better -.o

Thanks in advance!!
Nov 30 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
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
Nov 30 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.