0

I am stuck in a while True loop which I can't seem to break, any suggestions please:

command1 = transporterLink + " -m verify -f " + indir1 + " -u " + username + " -p " + password + " -o " + indir1 + "/VerifyLog.txt -s " + provider1 + " -v eXtreme"
master, slave = pty.openpty()

process = Popen(command1, shell=True, stdin=PIPE, stdout=slave, stderr=slave, close_fds=True)
stdout = os.fdopen(master)
while True:
    wx.Yield()
    line = stdout.readline()
    print line.rstrip()
    if not line:
        break
process.wait()
1
  • 1
    Do you ever get an empty line from stdout? Commented Feb 9, 2014 at 20:57

2 Answers 2

4

The simplest explanation is that you never get an empty line from stdout. Note that print line.rstrip() does not modify line; for example, if the last line ended with a newline, the loop would continue.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks NPE, any suggestions on how I could get out of this loop when at the end?
@speedyrazor You might consider if not line.strip(): instead.
0

Sorted. I know that at the end of the last line it will return one of two strings so just needed to search for either of these two:

process = Popen(command1, shell=True, stdin=PIPE, stdout=slave, stderr=slave, close_fds=True)
stdout = os.fdopen(master)
while True:
    wx.Yield()
    line = stdout.readline()
    line = line.rstrip()
    print line
    if "Returning 1" in line:
        break
    if "Returning 0" in line:
        break

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.