pexpect如何使用用户输入启动程序?

时间:2019-07-15 16:26:41

标签: python pexpect

在我的脚本中,有一个函数可以在easy-rsa的帮助下创建客户端密钥和证书:

def create_cert(client_name, country, oblast, city, company, unit, cn, name, email): 

    os.chdir('easy-rsa/')
    command = "source vars"
    my_call = subprocess.call(command, shell=True, executable='/bin/bash')

    command_to_run = " ".join(['./build-key', client_name])
    print(command_to_run)
    child = pexpect.spawn(command_to_run)
    string_to_expect = ".*?"
    print(child.after)

    child.expect(string_to_expect)
    child.sendline(country)
    print(child.after)

    child.expect(string_to_expect)
    child.sendline(oblast)
    print(child.after)

以及更多“期望”和“终点线”。 功能结束:

child.expect(pexpect.EOF, timeout=None)
os.chdir(path_to_project)

这是我运行脚本时得到的:

/home/marka/Документы/Practice/easy-rsa
NOTE: If you run ./clean-all, I will be doing a rm -rf on /home/marka/Документы/Practice/easy-rsa/keys
./build-key client10
None
b''
b''
b''

如何通过用户输入启动easy-rsa(构建键)?

0 个答案:

没有答案