使用pexp控制Xilinx XSCT时出错

2024-09-29 23:32:15 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是Xilinx的XSCT控制台的包装示例。(它只是将XSCT应答回显到控制台并向XSCT发出命令)

#xsct_wrapper.py

import sys
import os
import re
import pexpect

# Path of Xilinx'XSCT executable:
xsct = '/opt/Xilinx/Vivado/2017.4/bin/xsdb'
prompt = '% '

# Start XSCT
p = pexpect.spawn(xsct)

# Wait for prompt
p.expect(prompt, timeout = 5)

# print the texts
print(p.before.decode(), end='')
print(p.match.group(0).decode(), end='')


while True:

    # Wait and run a command.
    command = input()
    p.sendline(command)

    try:
        # Wait for prompt
        p.expect(prompt)

        # print the texts
        print(p.before.decode(), end='')
        print(p.match.group(0).decode(), end='')

    except pexpect.EOF:
        # The program has exited
        print('The program has exied... BY!')
        break

我的问题是,XSCT的答案没有对齐,或者根本就没有到达。下面是一个片段:

PC:~$ python3 xsct_wrapper.py
rlwrap: warning: your $TERM is 'xterm-256color' but rlwrap couldn't find it in the terminfo database. Expect some problems.

****** Xilinx System Debugger (XSDB) v2017.4
  **** Build date : Dec 15 2017-21:02:16
    ** Copyright 1986-2017 Xilinx, Inc. All Rights Reserved.


xsdb% puts hello
xsdb%                                    ((I hit enters here...))
xsdb%
xsdb% ello
xsdb%

虽然我以本机方式启动xsct,但它的工作方式与预期一致:

PC:~$ /opt/Xilinx/Vivado/2017.4/bin/xsdb
rlwrap: warning: your $TERM is 'xterm-256color' but rlwrap couldn't find it in the terminfo database. Expect some problems.

****** Xilinx System Debugger (XSDB) v2017.4
  **** Build date : Dec 15 2017-21:02:16
    ** Copyright 1986-2017 Xilinx, Inc. All Rights Reserved.


xsdb% puts hello
hello
xsdb%

我做错了什么?

(我已经尝试将包装器中的可执行文件从xsct更改为bash,然后它会按预期工作。缺陷是否位于XSCT程序中?)你知道吗

我使用:

  • 5.0.0-32-generic#34~18.04.2-Ubuntu SMP Thu 10月10日10:36:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • Python 3.6.8版
  • 预期==4.2.1
  • 万岁2017.4

Tags: theimporthellopromptx86commandendpexpect

热门问题