Terminal text becomes invisible after terminating subprocess

后端 未结 4 572
北恋
北恋 2021-01-04 02:06

After terminating an ffmpeg subprocess, the terminal gets messed up - typed characters are invisible! The input still works in that commands can be executed, b

相关标签:
4条回答
  • 2021-01-04 02:42

    As stated in this answer, ffmpeg expects data from stdin. You can run ffmpeg with the -nostdin flag and it will keep your terminal from hiding keystrokes.

    0 讨论(0)
  • 2021-01-04 03:03

    os.system('stty sane') worked for me. It reset settings making echo invisible.

    0 讨论(0)
  • 2021-01-04 03:05

    Change the script so that proc.terminate() is not used. You can stop an ffmpeg subprocess more politely with

      proc.send_signal(signal.SIGINT)
      proc.wait()
    

    This allows ffmpeg the chance to write whatever escape sequences it needs to restore the terminal.


    edit: discovered later- another tip to make ffmpeg behave better with Popen is to provide it a subprocess.PIPE or open(os.devnull) in the stdin handle. Otherwise, it seems to try to get input from the parent's stdin which can cause weird terminal behaviour. A running ffmpeg process is listening for '?' and 'q' input on stdin.

    0 讨论(0)
  • 2021-01-04 03:05

    do you communicate with the subprocess? in that case i would use pexpect which makes that type of setup very simple, perhaps you must wait for the command to finish? i.e.

     p = subprocess.Popen(argv, stdout=o, stderr=e)
     p.wait()
     if p.returncode != 0:
          print("problems")
    

    that's what i use on a dvd2h264 script i wrote a while back, never had any problems with it, but i don't redirect stdin/stderr to tmpfiles..

    0 讨论(0)
提交回复
热议问题