[Tutor] wrapping a command line tool
Kent Johnson
kent37 at tds.net
Fri Dec 15 17:21:15 CET 2006
Gonzillaaa wrote:
> Hello,
>
> I am using a command line tool that allows me to specify a serial
> port and either read from or write data to it. I would like to create
> a python module that wraps that functionality and allows me to
> manipulate the incoming data to present it in a table for instance
> (like top works) or maybe store it in a dictionary and drop it into a
> database at timed intervals.
>
> I am Python newbie so pointers to capture command line output and how
> to format it as a table for instance would be greatly appreciated.
If you are using a command-line tool that expects user input then I
think you need something like pexpect, however pexpect requires the pty
module which doesn't work on Windows so that may be a problem for you.
http://pexpect.sourceforge.net/
I suggest that a better approach might be to use pyserial which is
intended to give access to the serial port directly from Python and runs
on Windows, Linux and MacOSX.
http://pyserial.sourceforge.net/
Kent
More information about the Tutor
mailing list