stdin and py2exe

Thomas Heller theller at python.net
Wed Sep 14 19:38:58 CEST 2005


"Mike Tammerman" <mtammerman at gmail.com> writes:

> Hi,
>
> I want create a subprocess using Popen and pipe some input to it.
> Although everything works perfectly while executing python in, it
> doesn't work if I try with executables made by py2exe.
>
> I think, stdin is invalidated if the program becomes an executable.
> Because I get a "Bad file descriptor" exception in subprogram.py. I
> will be more than apreciated, if any suggestions occur.
>
> Thanks,
> Mike
>
> == main.py ==
> from subprocess import *
>
> pInput = Popen('python subprogram.py', stdin=PIPE, shell=True).stdin
> # pInput = Popen('subprogram.exe', stdin=PIPE, shell=True).stdin #
> doesn't work
>
> pInput.write('Data')
> pInput.close()
>
>
> == subprogram.py ==
> import sys
>
> input = sys.stdin.read()  # Throws a bad descriptor exception.
> print input

Can it be that you're building a windows exe of subprogram.py? I get the
error you describe when I do that,  for console programs it works -
both in the Python script and in the py2exe'd version.

This is, afaik, standard windows behaviour: GUI programs start with
stdin, stdout and stderr closed.

Thomas



More information about the Python-list mailing list