Search code examples
pythonlinuxcommand-linepexpect

File writing command in pexpect not behaving as I thought it would


There is a process that i can run from the command line which writes data to a file continuously until i tell it to stop, and can be accessed (read) while the process is running.

However, if I run the same command through pexpect, the file stays empty (although can be read) until I stop the pexpect instance. Only then will the file fill up with the data.

Is this just a feature of pexpect or am I doing something wrong here?

pexpect command:

child = pexpect.spawn('airodump-ng', ['-a', '-w', '/root/Desktop/TEST', '--output-format', 'csv', INTERFACE])

Solution

  • I have never used airodump-ng; if it is a fire and forget exercise (no interaction), you should be using pexpect.run() for non-interactive tasks such as ls -la

    results = pexpect.run('ls -la')
    

    If you need interaction, just put your args in one string...

    child = pexpect.spawn('airodump-ng -a -w /root/Desktop/TEST --output-format csv %s' % INTERFACE)