Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between subprocess module, envoy, sarge and pexpect?

I am thinking about making a program that will need to send input and take output from the various aircrack-ng suite tools. I know of a couple of python modules like subprocess, envoy, sarge and pexpect that would provide the necessary functionality. Can anyone advise on what I should be using or not using, especially as I'm new to python.

Thanks

like image 276
bananamana Avatar asked Jun 03 '12 18:06

bananamana


2 Answers

As the maintainer of sarge, I can tell you that its goals are broadly similar to envoy (in terms of ease of use over subprocess) and there is (IMO) more functionality in sarge with respect to:

  • Cross-platform support for bash-like syntax (e.g.use of &&, ||, & in command lines)
  • Better support for capturing subprocess output streams and working with them asynchronously
  • More documentation, especially about the internals and peripheral issues like threading+forking in the context of using subprocess
  • Support for prevention of shell injection attacks

Of course YMMV, but you can check out the docs, they're reasonably comprehensive.

like image 124
Vinay Sajip Avatar answered Sep 28 '22 04:09

Vinay Sajip


pexpect

In 2015, pexpect does not work on windows. Rumored to add "experimental" support in the next version, but this has been a rumor for a long time (I'm not holding my breath).

Having written many applications using pexpect (and loving it), I am now sorry because one of the things I love about python (that it is cross platform) is not true for my applications.

If you plan to ever add windows support, for the moment, avoid pexpect.

envoy

Not much activity in the last year. And few commits (12 total) since 2012. Not very promising for its future.

Internally it uses shlex in a way that is not compatible with windows paths (the commands must use '/' not '\' for directory separators). A workaround (when using pathlib) is to call as_posix() on path objects before passing them as commands. See this answer.

Getting access to the internal streams (i.e. I want to parse the output to have some updating scrollbars), seems possible but is not documented.

sarge

Works on windows out-of-the-box and has an expect() method that should provide functionality similar to pexpect (allowing me to update a scrollbar). Recent activity, but it is hosted on gitlab and bitbucket (very confusing).

Personal Conclusion

I'm moving from pexpect to sarge for future development. Seems to provide similar feature set to pexpect and supports windows.

like image 42
codyzu Avatar answered Sep 28 '22 04:09

codyzu