首页 > 解决方案 > 使用 Python 打开并写入终端

问题描述

我已经阅读了很多关于运行 python 代码的帖子,这些代码可以打开终端并使用以下内容在其中写入:

    PIPE_PATH = "/tmp/my_pipe"
    if os.path.exists(PIPE_PATH):
        os.remove(PIPE_PATH)
        os.mkfifo(PIPE_PATH)

    # open terminal that reads from your pipe file
    #k = subprocess.Popen('ls -la',shell=True)
    a = subprocess.Popen(['gnome-terminal', '-e', 'tail --follow {0}'.format(PIPE_PATH)])

message = "JLinkExe -device FE310 -if JTAG -speed 4000 -jtagconf -1,-1 -autoconnect 1\n" 
with open(PIPE_PATH, "w") as p: 
p.write(message)

由于某种原因,打开的终端是空白终端,有没有办法解决这个问题?在此处输入图像描述

标签: pythonterminal

解决方案


推荐阅读