【问题标题】:process run by pexpect.run() method terminates abruptlypexpect.run() 方法运行的进程突然终止
【发布时间】:2019-02-05 04:08:39
【问题描述】:

当我在下面运行代码时,我看到进程甚至在完成之前就终止了。 我通过手动运行命令来验证命令只是工作文件。 cmssso-util 产生大约 1200 行的输出。这可能是缓冲区问题吗? 我通过将“ls -ltr”分配给变量命令来验证脚本工作正常。 以下链接中的参考文档: https://pexpect.readthedocs.io/en/stable/_modules/pexpect/run.html

  • 我尝试使用 'bash -c' 为命令添加前缀,但未能解决此问题。
  • 我试图找出 pexpect 如何确定终止进程,但仍然无法获得任何明确的文档。 请帮帮我。
导入预期 command = "cmsso-util domain-repoint -m execute --src-emb-admin " + 'sourceVcAdmin' + " --replication-partner-fqdn " + 'destVc' + " --replication-partner-admin " + ' destVcAdmin' + " --dest-domain-name " + 'destDomain' print("运行命令:" + 命令) (command_output, exitstatus) = pexpect.run(command ,withexitstatus=1, events={'输入源嵌入式 vCenter Server 管理员密码:':'\r\n','输入复制伙伴平台服务控制器管理员密码:':' \r\n','所有 Repoint 配置设置都正确;继续?(.*)' : 'Y\r\n'}) print("----命令输出------------") 打印(命令输出) 打印(” - - - - - - - - - - - - - - -”) 断言 exitstatus 为 0 ,“执行失败” print("成功完成嵌入式跨域重指向")

【问题讨论】:

  • 命令有输出吗?该输出是否表明任何错误,或者只是意外截断?
  • @jasonharper :日志没有显示任何错误,进程意外终止。手动运行时相同的命令进程完成,没有任何问题。最后几行日志在这里`:/usr/lib/vmware-sca/lib/lookup-client.jar:/usr/lib/vmware-sca/lib/*:/usr/lib/vmware-sca/lib\' , \'-Dlog4j.configuration=tool-log4j.properties\', \'com.vmware.vim.lookup.client.tool.LsTool\', \'get\', \'--url\', \' vcsa.st.local:443/lookupservice/sdk\', \'--id\', \'f09ee5e1-0c3a-4808-9eee-8bc8bb0f3bd1\', \'--as-spec\']\r\n'`

标签: python jenkins pexpect


【解决方案1】:

我可以使用以下代码解决此问题:

    import pexpect
try :
        command = "cmsso-util domain-repoint -m execute  --src-emb-admin " + 'sourceVcAdmin' + " --replication-partner-fqdn " + 'destVc' + " --replication-partner-admin " + 'destVcAdmin' + " --dest-domain-name " +    'destDomain'
        print("Running command  : " + command) 
        child = pexpect.spawn(command, timeout=3000,maxread=12000)
        child.expect (['Enter Source embedded vCenter Server Admin Password :'],timeout=40000)
        child.sendline(<password>)
        child.expect (['Enter Replication partner Platform Services Controller Admin Password :'],timeout=40000)
        child.sendline(<password>)
        child.expect (['All Repoint configuration settings are correct; proceed?(.*)'],timeout=40000)
        child.sendline('Y')
        child.expect(pexpect.EOF)
        print(child.before)   
        assert(child.status == 0 , "Operation Failed!", "Successfully Completed Embedded Cross Domain Re-pointing")
except:
    print("Exception was thrown")
    print("debug information:")
    print(str(child))
    child.close()
    exit(1)

这是通过增加默认 child = pexpect.spawn(command, timeout=600,maxread=8000)value 和 ma​​xread 参数来完成的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多