Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion communicate with external process via pty

Received: by 10.66.72.73 with SMTP id b9mr4950112pav.9.1349842021636;
        Tue, 09 Oct 2012 21:07:01 -0700 (PDT)
Path: t10ni23661243pbh.0!nntp.google.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!foggy!not-for-mail
From: Tim Arnold <Tim.Arn...@sas.com>
Newsgroups: comp.lang.python
Subject: communicate with external process via pty
Date: Tue, 09 Oct 2012 15:44:49 -0400
Organization: SAS Inc.
Lines: 30
Message-ID: <k51uri$kqq$1@foggy.unx.sas.com>
NNTP-Posting-Host: d74158.na.sas.com
Mime-Version: 1.0
X-Trace: foggy.unx.sas.com 1349811890 21338 10.40.16.227 (9 Oct 2012 19:44:50 GMT)
X-Complaints-To: usenet@unx.sas.com
NNTP-Posting-Date: Tue, 9 Oct 2012 19:44:50 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0
Bytes: 1801
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I have an external process, 'tralics' that emits mathml when you feed it 
latex equations. I want to get that mathml into a string.

The problem for me is that tralics wants to talk to a tty and I've never 
done that before; it basically starts its own subshell.

I have the following code which works for simple things. I'm not sure 
this is the best way though: basically I got this from google...

import os,sys
import subprocess
import shlex
import pty
cmd =  'tralics --interactivemath'

(master, slave) = pty.openpty()
p = subprocess.Popen(shlex.split(cmd),close_fds=True,
                      stdin=slave,stdout=slave,stderr=slave)

os.read(master,1024)                # start the process
os.write(master,'$\sqrt{x}$\n')     # feed it an equation
mathml.append(os.read(master,1024)) # get the mathml in a string

os.write(master,'$\sqrt{x}$\n')     # feed more equations
mathml.append(os.read(master,1024)) # get the next string


Any suggestions for improvement?
thanks,
--Tim