Python string-Vergleich

Habe ich eine python-Funktion, die macht einen Teilprozess Aufruf ein shell-Skript, das gibt 'true' oder 'false'. Ich bin speichern der Ausgabe aus subprocess.communicate() versuche zu tun return output == 'true' aber es gibt False jeder Zeit. Ich bin nicht allzu vertraut mit python, aber das Lesen über string-Vergleiche sagt, Sie können strings vergleichen mit ==, !=, etc.

Hier der code:

def verifydeployment(application):
    from subprocess import Popen, PIPE
    import socket, time

    # Loop until jboss is up.  After 90 seconds the script stops looping; this
    # causes twiddle to be unsuccessful and deployment is considered 'failed'.
    begin = time.time()
    while True:
        try:
            socket.create_connection(('localhost', 8080))
            break
        except socket.error, msg:
            if (time.time() - begin) > 90:
                break
            else:
                continue

    time.sleep(15)  # sleep for 15 seconds to allow JMX to initialize

    twiddle = os.path.join(JBOSS_DIR, 'bin', 'twiddle.sh')
    url = 'file:' + os.path.join(JBOSS_DIR, 'server', 'default', 'deploy', os.path.basename(application))

    p = Popen([twiddle, 'invoke', 'jboss.system:service=MainDeployer', 'isDeployed', url], stdout=PIPE)
    isdeployed = p.communicate()[0]

    print type(isdeployed)
    print type('true')
    print isdeployed
    return isdeployed == 'true'

Ausgabe:

<type 'str'> # type(isdeployed)
<type 'str'> # type('true')
true         # isdeployed

aber False immer zurückgegeben. Ich habe auch versucht return str(isdeployed) == 'true'.

Bist du sicher, dass es keine neue Zeile wird nach "wahr"? Vielleicht versuchen isdeployed.strip() == 'true'

InformationsquelleAutor ravun | 2010-03-25

Schreibe einen Kommentar