0
我期待運行qemu客人,登錄並執行一些任務。我現在用的是以下QEMU客人自動化使用python pexpect
- 的Ubuntu 16.04作爲主機
- QEMU 2.10.0-RC4
- python3
- Pexpect的4.0.1
我已經嘗試了代碼作爲automation of processes by python簡稱
但是,我總是得到超時異常。任何幫助將不勝感激。請在下面找到我的代碼片段和例外。
代碼:
import pexpect
QEMU_RUN_CMD='qemu-system-arm -nographic -kernel kernel.bin -M versatilepb -drive file=core-image-minimal-qemuarm.rootfs.ext4,if=virtio,format=raw,cache=writeback -m 128 -append "root=/dev/vda rw console=ttyAMA0,115200 console=tty mem=128M highres=off rootfstype=ext4"'
child = pexpect.spawn(QEMU_RUN_CMD)
child.expect('login: ')
child.sendline('root')
child.expect('# ')
child.sendline('ls -l')
child.expect(pexpect.EOF)
output = child.before
print ("{}".format(output))
異常
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 97, in expect_loop
incoming = spawn.read_nonblocking(spawn.maxread, timeout)
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 452, in read_nonblocking
raise TIMEOUT('Timeout exceeded.')
pexpect.exceptions.TIMEOUT: Timeout exceeded.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ref.py", line 11, in <module>
child.expect(pexpect.EOF)
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 315, in expect
timeout, searchwindowsize, async)
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 339, in expect_list
return exp.expect_loop(timeout)
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 104, in expect_loop
return self.timeout(e)
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 68, in timeout
raise TIMEOUT(msg)
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x7ff6843fc898>
command: /usr/local/bin/qemu-system-arm
args: ['/usr/local/bin/qemu-system-arm', '-nographic', '-kernel', 'zImage--4.4.26+git0+3030330b06_187bcc13f3-r0-qemuarm-20170810070254.bin', '-M', 'versatilepb', '-drive', 'file=core-image-minimal-qemuarm-20170810070254.rootfs.ext4,if=virtio,format=raw,cache=writeback', '-m', '128', '-append', 'root=/dev/vda rw console=ttyAMA0,115200 console=tty mem=128M highres=off rootfstype=ext4']
searcher: None
buffer (last 100 chars): b'0:38 foo.txt\r\r\ndrwxr-xr-x 4 root root 1024 Aug 24 09:14 sect_test\r\r\[email protected]:~# '
before (last 100 chars): b'0:38 foo.txt\r\r\ndrwxr-xr-x 4 root root 1024 Aug 24 09:14 sect_test\r\r\[email protected]:~# '
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 10707
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
謝謝。我犯了一個嚴重的錯誤。 – user8514760