9

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

smci
  • 32,567
  • 20
  • 113
  • 146
bananamana
  • 485
  • 1
  • 9
  • 19
  • 1
    I haven't heard of most of those libraries, but in general if there's a standard module that does everything I need, I'd favor it over any 3rd-party libraries. – Lev Levitsky Jun 03 '12 at 18:54
  • 1
    You may need `pexpect` instead of `subprocess` when you want bidirectional communication with a process. I don't know the other two libraries. – Fred Foo Jun 03 '12 at 21:01

3 Answers3

14

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.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
  • 1
    Testing sarge vs envoy (I am replacing pexpect to add windows support to my application), I found that envoy uses shlex.This results in native windows paths not being supported (shlex removes "\" chars). This can be worked around (when using pathlib) by calling [as_posix()](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.as_posix) before passing paths to envoy. However, sarge works with windows paths out-of-the-box. – codyzu Sep 11 '15 at 11:06
  • Sarge has unfortunately not been updated since 2018 (about two years stale now), and was left in "beta" stage. It otherwise looked promising! – Andy Aug 11 '20 at 22:01
  • @Andy as the maintainer of `sarge` I still respond to feature requests and bug reports where feasible - there have no updates since 2018 since it does what I need and there have been no bug reports or feature requests that I can progress. – Vinay Sajip Aug 13 '20 at 05:21
  • @VinaySajip it sounds like you no longer consider to be "beta" then. Would you care to make a non-beta release? – Andy Aug 31 '20 at 17:31
  • @Andy was released on 24 Aug 2020: https://pypi.org/project/sarge/0.1.6/ – Vinay Sajip Aug 31 '20 at 18:53
4

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.

Community
  • 1
  • 1
codyzu
  • 541
  • 3
  • 18
  • So what about `subprocess`? It still works, it just has annoying syntax. And it works on all platforms, unlike some of these others. – smci Mar 17 '20 at 02:46
2

subprocess - is a standard library module, so it'll be available with python installation. But it has a reputation of hard to use since it's api is non-intuitive.

envoy - is a third party module that wraps around subprocess. It was written to be an easy to use alternative to subprocess. The author of envoy Kenneth Reitz is famous for his Python for Humans philosophy.

I'm not familiar with the other two.

Amjith
  • 22,626
  • 14
  • 43
  • 38