leong leong - 1 year ago 196
Python Question

Python: Hide sub-process print out on the terminal and continue the script while sub is running

is there a way to use python2.6 with either

to run two tasks? Example the script will run "
" first then this process is sub and is hidden(meaning will not print out from terminal) after which continue run the rest of the script which contain "
" function of scapy. I been researched but I only found windows version and python3. By the way I running on debian.

Answer Source

Use subprocess.Popen in combination with subprocess.PIPE:

p = Popen(['airodump-ng', …], stdin=PIPE, stdout=PIPE, stderr=PIPE)

If you want to wait until the process has finished use:

stdout, stderr = p.communicate()

If you omit the code above airodump-ng will run in the background and produce no visible output, while you can continue with your python code.

Another method would be to use os.devnull to redirect the output of airodump-ng to, this will completly get rid of any output produced:

devnull = os.open(os.devnull, os.O_WRONLY)
p = Popen(['airodump-n', …], stdout=devnull, stderr=devnull)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download