Search code examples
pythonsubprocesspopen

Test if a Popen process is waiting for input


I start a process with POpen and under normal circuimstances it should just do a job and write things to stdout which I then capture. In exceptional cases the process will fallback to an interactive mode and wait for user input. How can I detect that case and react appropriately?


Solution

  • You can always send something to sub-process even it read nothing. So you just sent to sub-process, if it works OK, then those staff you sent will be dropped, if it failed, then you will read response.