<html>
<body>
<blockquote type=cite class=cite cite="">
<dl>
<dd>Hi<br><br>

<dd>I have a legacy (FORTRAN) program called POLY.EXE which asks the user
interactively for three inputs (file names) from the keyboard.&nbsp; I
would like to run this program in batch and tried to replace the
interactive prompts with file names stored in a separate file using this
Python script:<br><br>

<dd>import subprocess<br><br>

<dd>try:<br>

<dd>&nbsp;&nbsp; poly_file =
file(&quot;poly_files.txt&quot;,&quot;r&quot;)<br>

<dd>except:<br>

<dd>&nbsp;&nbsp; print &quot;Could not open input file&quot;<br>

<dd>else:<br>

<dd>&nbsp;&nbsp; x = subprocess.Popen(args=&quot;poly.exe&quot;,
stdin=poly_file)<br>

<dd>&nbsp;&nbsp; x.wait()<br><br>

<dd>poly_files.txt contains the three file names as follows:<br><br>

<dd>polyin.dat<br>

<dd>polyout.dat<br>

<dd>polyout.plt<br><br>

<dd>On execution, I get these error messages<br>

<dd>Traceback (most recent call last):<br>

<dd>&nbsp;File &quot;C:/Projects/Active/Alun/test_poly.py&quot;, line 4,
in -toplevel-<br>

<dd>&nbsp;&nbsp; x = subprocess.Popen(args=&quot;poly.exe&quot;,
stdin=poly_file)<br>

<dd>&nbsp;File &quot;C:\Python24\lib\subprocess.py&quot;, line 533, in
__init__<br>

<dd>&nbsp;&nbsp; (p2cread, p2cwrite,<br>

<dd>&nbsp;File &quot;C:\Python24\lib\subprocess.py&quot;, line 607, in
_get_handles<br>

<dd>&nbsp;&nbsp; c2pwrite = self._make_inheritable(c2pwrite)<br>

<dd>&nbsp;File &quot;C:\Python24\lib\subprocess.py&quot;, line 634, in
_make_inheritable<br>

<dd>&nbsp;&nbsp; DUPLICATE_SAME_ACCESS)<br>

<dd>WindowsError: [Errno 6] The handle is invalid<br><br>

<dd>So, it looks like something is wrong with the way I am redirecting
stdin, but I have no idea what the problem is.&nbsp; Any suggestions
gratefully received<br><br>

</dl><br>
I've not done much with subprocess, but I know you can use the
subprocess.PIPE to redirect stdin/stdout. <br><br>
This may be of some help too,<br>
&nbsp;<a href="http://www.oreillynet.com/onlamp/blog/2007/08/pymotw_subprocess_1.html">
http://www.oreillynet.com/onlamp/blog/2007/08/pymotw_subprocess_1.html</a>
<br><br>
-Wayne<br>
</blockquote><br>
Wayne<br><br>
I did try using stdin but got the same problem.&nbsp; I also hacked the
following from the website you suggested:<br><br>
import subprocess<br><br>
x =
subprocess.Popen(args=&quot;poly.exe&quot;,stdin=subprocess.PIPE)<br><br>
for item in [&quot;polyin.dat&quot;, &quot;polyout.dat&quot;,
&quot;polyout.plt&quot;]:<br>
&nbsp;&nbsp;&nbsp; x.stdin.write('%s\n' % item)<br><br>
but got the same error message<br><br>
Best regards<br><br>
Alun<br><br>
<br>
</body>
</html>