栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在嵌入式终端中发出命令

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在嵌入式终端中发出命令

您可以通过写入伪终端从属子进程来与外壳进行交互。这是一个如何工作的演示。这个答案多少基于对
Linux伪终端
的回答
:执行从一个终端发送到另一个终端的字符串

关键是要获得xterm使用的伪终端(通过

tty
命令),并将方法的输出和输入重定向到该伪终端文件。例如
ls < /dev/pts/1 >/dev/pts/1 2> /dev/pts/1

注意

  1. xterm子处理程序泄漏(
    os.system
    不建议使用,尤其是对于
    &
    说明不推荐使用。请参阅
    suprocess
    模块)。
  2. 可能无法以编程方式找到使用了哪个tty
  3. 每个命令都在新的suprocess中执行(仅显示输入和输出),因此状态修改命令(例如xterm)

    cd
    以及xterm的上下文(
    cd
    在xterm中)无效

    from Tkinter import *from os import system as cmd

    root = Tk()
    termf = frame(root, height=700, width=1000)
    termf.pack(fill=BOTH, expand=YES)
    wid = termf.winfo_id()

    f=frame(root)
    Label(f,text=”/dev/pts/”).pack(side=LEFT)
    tty_index = Entry(f, width=3)
    tty_index.insert(0, “1”)
    tty_index.pack(side=LEFT)
    Label(f,text=”Command:”).pack(side=LEFT)
    e = Entry(f)
    e.insert(0, “ls -l”)
    e.pack(side=LEFT,fill=X,expand=1)

    def send_entry_to_terminal(args):
    “”“
    args needed since callback may be called from no arg (button)
    or one arg (entry)
    “”“
    command=e.get()
    tty=”/dev/pts/%s” % tty_index.get()
    cmd(“%s <%s >%s 2> %s” % (command,tty,tty,tty))

    e.bind(““,send_entry_to_terminal)
    b = Button(f,text=”Send”, command=send_entry_to_terminal)
    b.pack(side=LEFT)
    f.pack(fill=X, expand=1)

    cmd(‘xterm -into %d -geometry 160x50 -sb -e “tty; sh” &’ % wid)

    root.mainloop()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/659681.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号