pexpect equivalent of Expect's “send_user”

前端 未结 2 1688
无人共我
无人共我 2021-01-23 23:57

As a continuation from my previous question on building interactive option menus in pexpect, print statements within an interact input filter do not get sent to stdout until aft

相关标签:
2条回答
  • 2021-01-24 00:23

    I found that printing to the screen gave a weird offset based on what had previously been printed out by the spawned process and that the spawned processes next output was also offset a weird amount. What I ended up doing was:

        sys.stdout.write(f'\n\rsomething\r\n')
        sys.stdout.flush()
    

    This prints my something at the beginning of a new line, then starts the spawned processes output at the beginning of the next line.

    0 讨论(0)
  • 2021-01-24 00:26

    Don't really know why print()'ed data is not automatically flushed when interacting with the spawned child but you can flush it explicitly so it would show up realtime:

    print('something')
    sys.stdout.flush()
    

    or just use (only for python3)

    # .raw is not buffered
    sys.stdout.buffer.raw.write('something')
    
    0 讨论(0)
提交回复
热议问题