Ich versuche, ein interaktives Python-Skript mit Pexpect zu automatisieren. Aber es geht nicht weiter, nachdem die Kontrolle zurückkehrt.Interagieren mit einem Python-Skript innerhalb von Pexpect
Hier ist ein Mock Up Skript versuchen, das gleiche zu simulieren.
---------------- python script(script.py) -----------------
def issue_command():
print "********** in issue_command ********"
def dummy_check():
print "********** in dummy_check ********"
raw_input("Now Press enter for next command")
issue_command()
if __name__ == "__main__":
dummy_check()
--------------------------------Pexpect script(pexp.py)-----------------------
import pexpect
import sys
def quick_test():
pobj = pexpect.spawn("/bin/bash")
pobj.logfile = sys.stdout
pobj.sendline("script.py")
pobj.expect("Now Press enter for next command")
print "\n1st part is done. Now execute the oil command"
pobj.sendline()
if __name__ == "__main__":
quick_test()
-------------------------------------------------------------------
Ich erwarte, dass der Ausgang folgt.
$python pexp.py
********** in dummy_check ********
Now Press enter for next command -------------------> It should wait here. Upon pressing enter it should print the next line.
********** in issue_command ********
$
Stattdessen drucken Sie es nicht die zweite Zeile heißt die pexpect nicht mit dem Skript interagieren konnte, nachdem er zurück dazwischen.
$ python pexp.py
./script.py
********** in dummy_check ********
Now Press enter for next command -----> It ignored sendline() and did not execute issue_command function.
$
Ich habe auch versucht, das Skript (script.py) direkt in der pexpect.spawn Passing() anstelle einer anderen Schale zu schaffen (/ bin/bash). Es hat nicht geholfen. Ich bin mir nicht sicher, was ich falsch mache. Kann jemand bitte beraten?
Danke.