gpt4 book ai didi

python - 无法使用 child.before 获取数据

转载 作者:太空宇宙 更新时间:2023-11-04 10:55:45 25 4
gpt4 key购买 nike

    ip="99.78.992.02"
prompt="\$"
log_file_handle = open(os.path.join(os.getcwd(), "log_file"),"a")
child = pexpect.spawn("ssh abc@%s" % ip, logfile=log_file_handle) # this works because I have public-private key set up
child.sendline("ls -l")
child.expect(prompt)
print "child.before %s" % child.before
print "child.after %s" % child.after

我得到的响应是:

    child.before  
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-67-generic-pae i686)

* Documentation: https://help.ubuntu.com/

360 packages can be updated.
305 updates are security updates.

New release '14.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.



*** /dev/sda4 will be checked for errors at next reboot ***
*** /dev/sda2 will be checked for errors at next reboot ***

No mail.
Last login: Wed Mar 4 13:44:40 2015 from 10.49.92.49
ls
abc@mycomputer:~
child.after $

为什么我在 child.before 中没有得到“ls -l”的输出?有人可以对此发表评论吗?

最佳答案

正如 J.F. Sebastian 在评论中所说,我必须等待提示才能发出命令。

关于python - 无法使用 child.before 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28865769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com