Interacting with a process that I ran with subprocess module

Diez B. Roggisch deets at nospam.web.de
Fri Jun 9 10:56:29 EDT 2006


py.adriano at gmail.com schrieb:
> Hi folks,
> 
> I'm trying to use the nmap runtime interaction feature while using it
> with the subprocess module. For those not familiar with nmap, the
> runtime interaction feature allow users to get informations about the
> scan stats during the nmap execution. More at:
> http://www.insecure.org/nmap/man/man-runtime-interaction.html
> If someone want to try, just run nmap and try to type some keys to see
> what happens. This only works with nmap 4.00 and above.
> 
> Ok.. What I've tried is shown below:
> 
> from subprocess import Popen, PIPE
> nmap = Popen("nmap -T3 -A 10.0.0.1-254", stdin=PIPE, stdout=PIPE,
> stderr=PIPE, shell=True, bufsize=1)
> 
> To interact with nmap, I tried:
> 
> nmap.communicate("?")
> 
> And I tried this, also:
> 
> nmap.stdin.write("?")
> nmap.stdout.read()
> 
> What's wrong? Is that suposed to be this way? Is there a better way to
> interact with it that I've missed? Any help is very welcome. Thanks in
> advance!

Programs that interact with users usually require a terminal to be run 
from. This is not the case when using pipes. Use pexpect.

Diez



More information about the Python-list mailing list