简体   繁体   中英

How to get number output from pexpect

I'm using pexpect to handle two programs made by C.

The problem is that I have to get an integer. I want to have two integers printed from two programs, but all I know is pexpect.expect(['0','1','...','9']) . I want to get whole integer (with int scale). How can I get this?

(Expected code)

cmd_1 = pexpect.spawn('./program1')
cmd_2 = pexpect.spawn('./program2')
n_1 = pexpect.expect('something')
n_2 = pexpect.expect('something')
print("Number 1 : {} Number 2 : {}".format(n_1,n_2))

.expect() uses regular expressions. Therefore, use either \\\\d or [0-9] . You will still need to convert it to an integer, however. One more thing: it should be cmd1.expect and cmd2.expect , not pexpect.expect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM