Search code examples
pexpect

How to use pexpect to manage processes, but just redirect all output to /dev/null


I have a python script that starts a bunch of processes, but doesn't use the expect features to interact with processes. So I encounter issues where it seems the stdout buffer gets full and causes processes stdout to block. Is there a way to just have stdout/stderr redirected to /dev/null or just flushed? I have tried using logfile feature and opening /dev/null, but this still requires reading from process. Is there a way to do this?

Thanks.


Solution

  • You can direct all output to /dev/null so there will be no data waiting to be read. For example:

    pexpect.spawn('/bin/bash', ['-c', '/your/command ... > /dev/null 2>&1'])