python - pexpect did not block my script with pexpect.expect -


i making task scheduler pexpect of python.
implemented simple idea:

term = spawnu('tcsh') # need tcsh instead of default bash term.sendline('first_task') term.expect('my_shell_prompt') # when parent receive prompt means end of previous task. term.sendline('second_task') ...(and on) 

but found pexpect.expect did not block line:

term.expect('my_shell_prompt') # go through line before finish of previous task. 

since works matching pattern set last output of previous task. suspect pexpect.expect matched my_shell_prompt before child starts job. have add delay before matching. however, happens if add delay before pexect.expect.

time.sleep(2)  # delay 2 second  term.expect('my_shell_prompt') 

does know how debug this? appreciate.

i think found answer myself.
pexpect not distinguish echoed command , output child.
difficult accomplish previous attempt.

i workarounded saving check code in txt file. such file feedback child calling 'cat' in child.
example:

#check_code.txt ----your job done----  #in testpexpect.py term.sendline('cat check_code.txt')  # prevents matching echoed command term.expect('----your job done----') # blocks , matches 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -