<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        line-height:normal;
        font-size:12.0pt;
        font-family:"Times New Roman";
        color:windowtext;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {margin:0in;
        margin-bottom:.0001pt;
        line-height:normal;
        font-size:10.0pt;
        font-family:"Courier New";
        color:windowtext;}
p
        {margin-top:0in;
        margin-right:0in;
        margin-bottom:12.0pt;
        margin-left:0in;
        line-height:15.0pt;
        font-size:8.5pt;
        font-family:Verdana;
        color:black;}
span.code1
        {font-family:"Lucida Console";
        color:#007700;
        background:#EEEEEE;
        font-weight:bold;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 77.95pt 1.0in 77.95pt;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>David,<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>The subprocess module doesn't work for interactive programs (I think)
(see appended pexpect faq).<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>So instead, I was trying to get something like the following working:<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>import simnow # import complex simnow C++
application<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>simnow.start() # spawn simnow's main
method<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>output1 = simnow.sendCommand(&quot;load
platform x&quot;) # blocking call to a single simnow C++ functions<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'># This is our real current goal, but if I
get this working, we might consider exposing other simnow functionality to the simnow
python module.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>disutils is listed in the extend/embed python doc (http://www.python.org/doc/ext/ext.html).&nbsp;
This doc seems to be saying that disutils is a cross-plaform way to build a python
module (&quot;extend python&quot;).<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>Chapter 3 - disultils cross-platform build.&nbsp; Chapter 4 - do it
yourself windows build.&nbsp; Chapter 5 - do it yourself unix build.&nbsp; Chapter
4 says, &quot;<font color=black><span style='color:black'>Module authors are
encouraged to use the distutils approach for building extension modules,
instead of the one described in this section.</span></font>&quot;<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>--Thanks<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><b><font size=2 color=navy face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:navy;font-weight:bold'>subprocess
- &quot;appended comments&quot;<o:p></o:p></span></font></b></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'># This doesn't work<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>self.simnow =
Popen(executable=(os.getcwd() + '/simnow'), args=simnowCmd, stdin=PIPE,
stdout=PIPE, stderr=PIPE)<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>self.simnow.stdin.write(&quot;open
stuff&quot;)<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>print self.simnow.stdout.read()<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Why doesn't it work?&nbsp; The following
is from the pexect FAQ<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p><b><font size=1 color="#333333" face=Verdana><span style='font-size:8.5pt;
color:#333333;font-weight:bold'>Q: Why not just use a pipe (popen())?</span></font></b><font
color="#333333"><span style='color:#333333'><o:p></o:p></span></font></p>

<p><font size=1 color="#333333" face=Verdana><span style='font-size:8.5pt;
color:#333333'>A: A pipe works fine for getting the output to non-interactive
programs. If you just want to get the output from </span></font><span
class=code1><b><font color="#007700" face="Lucida Console">ls</font></b></span><font
color="#333333"><span style='color:#333333'>, </span></font><span class=code1><b><font
color="#007700" face="Lucida Console">uname</font></b></span><font
color="#333333"><span style='color:#333333'>, or </span></font><span
class=code1><b><font color="#007700" face="Lucida Console">ping</font></b></span><font
color="#333333"><span style='color:#333333'> then this works. Pipes do not work
very well for interactive programs and pipes will almost certainly fail for
most applications that ask for passwords such as telnet, ftp, or ssh.<o:p></o:p></span></font></p>

<p><font size=1 color="#333333" face=Verdana><span style='font-size:8.5pt;
color:#333333'>There are two reasons for this. <o:p></o:p></span></font></p>

<p><font size=1 color="#333333" face=Verdana><span style='font-size:8.5pt;
color:#333333'>First an application may bypass stdout and print directly to its
controlling TTY. Something like SSH will do this when it asks you for a
password. This is why you cannot redirect the password prompt because it does
not go through stdout or stderr.<o:p></o:p></span></font></p>

<p><font size=1 color="#333333" face=Verdana><span style='font-size:8.5pt;
color:#333333'>The second reason is because most applications are built using
the C Standard IO Library (anything that uses </span></font><span class=code1><b><font
color="#007700" face="Lucida Console">#include &lt;stdio.h&gt;</font></b></span><font
color="#333333"><span style='color:#333333'>). One of the features of the stdio
library is that it buffers all input and output. Normally output is <b><i><span
style='font-weight:bold;font-style:italic'>line buffered</span></i></b> when a
program is printing to a TTY (your terminal screen). Everytime the program
prints a line-feed the currently buffered data will get printed to your screen.
The problem comes when you connect a pipe. The stdio library is smart and can
tell that it is printing to a pipe instead of a TTY. In that case it switches
from line buffer mode to <b><i><span style='font-weight:bold;font-style:italic'>block
buffered</span></i></b>. In this mode the currently buffered data is flushed
when the buffer is full. This causes most interactive programs to deadlock.
Block buffering is more efficient when writing to disks and pipes. Take the
situation where a program prints a message &quot;Enter your user name:\n&quot;
and then waits for you type type something. In block buffered mode, the stdio
library will not put the message into the pipe even though a linefeed is
printed. The result is that you never receive the message, yet the child
application will sit and wait for you to type a response. Don't confuse the
stdio lib's buffer with the pipe's buffer. The pipe buffer is another area that
can cause problems. You could flush the input side of a pipe, whereas you have
no control over the stdio library buffer. <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><a
href="http://pexpect.sourceforge.net/%23faq"
title="blocked::http://pexpect.sourceforge.net/#faq">http://pexpect.sourceforge.net/#faq</a><o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>What's wrong with pexpect?&nbsp; It
doesn't work on Windows.&nbsp; Python COM is an alternative, but we are trying
to find a clean unified cross-platform solution.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>Peter Mowry (&quot;Pem&quot;)<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>SimNow Team, Software Engineer<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>AMD Organization<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>-----Original Message-----<br>
From: David Arnold [mailto:david@mantara.com] <br>
Sent: Saturday, May 12, 2007 10:00 PM<br>
To: Mowry, Peter<br>
Cc: distutils-sig@python.org<br>
Subject: Re: [Distutils] Python module to: Talk to stdout/stdin for 64-bit
Windows/Linux C++ application?</span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>--&gt;&quot;Peter&quot; == Mowry, Peter &lt;peter.mowry@amd.com&gt;
writes:<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; My team's application does regressions by controlling
our<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; 64-bit Windows/Linux C++ application (SimNow,<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; www.amd.com/simnow) via stdout/stdin with
(&quot;pexpect&quot; for unix)<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; and (python COM objects) for Windows (b/c popen
doesn't work).&nbsp;<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; However, I am trying to replace this with a unified<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; windows/linux solution.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>have you looked at the subprocess module, part of the standard library<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>in Python 2.4 and later?<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; Does extending python with Disutils sound like the
simple and<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; clean way for my goal?&nbsp; Is there a simple
cookbook solution for<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>&nbsp; Peter&gt; my goal?<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>i don't think distutils is what you're after.&nbsp; distutils is about<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>producing installers for Python applications.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>d<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>