python与shell交互

之前用到了subprocess模块,但有人提出可能会导致阻塞,最近在网上看到了pexpect模块,操作起来就已经跟perl很像了。

import pexpect

child=pexpect.spawn("sac")
child.sendline("r test.sac")
child.sendline("div 100")
child.sendline("w over")
child.sendline("q")

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注