逐字打印命令的输出

问题描述

我正在尝试在Python中从控制台命令行打印实时输出

直接在控制台中运行我的命令时,它每秒输出1个字。我想在Python IDE中实现相同的目的。

现在,我的代码实时一次输出一行:

def get_out(payload):
  !chmod +rx ./mycommand
  command = ['./mycommand',payload]
  process = subprocess.Popen(command,stdout=subprocess.PIPE,universal_newlines=True)
  while True:
    output = process.stdout.readline()
    if output == '' and process.poll() is not None:
        break
    if output:
        print(output.strip())
  rc = process.poll()
  print(output)

我如何一次打印1个字?

编辑:我开始认为这不可能完成

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)