Python: Converting a tuple to a string with 'err'

Posted by skylarking on Stack Overflow See other posts from Stack Overflow or by skylarking
Published on 2010-04-07T11:39:05Z Indexed on 2010/04/07 11:43 UTC
Read the original article Hit count: 290

Filed under:
|
|
|
|

Given this :

import os
import subprocess

def check_server():

    cl = subprocess.Popen(["nmap","10.7.1.71"], stdout=subprocess.PIPE)
    result = cl.communicate()
    print result

check_server()

check_server() returns this tuple:

('\nStarting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:26 EDT\nInteresting ports on 10.7.1.71:\nNot shown: 1711 closed ports\nPORT   STATE SERVICE\n21/tcp open  ftp\n22/tcp open  ssh\n80/tcp open  http\n\nNmap done: 1 IP address (1 host up) scanned in 0.293 seconds\n', None)

Changing the second line in the method to

result, err = cl.communicate()

results in check_server() returning :

Starting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:27 EDT
Interesting ports on 10.7.1.71:
Not shown: 1711 closed ports
PORT   STATE SERVICE
21/tcp open  ftp
22/tcp open  ssh
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.319 seconds

Looks to be the case that the tuple is converted to a string, and the \n's are being stripped.... but how? What is 'err' and what exactly is it doing?

© Stack Overflow or respective owner

Related posts about python

Related posts about string