473,395 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

stdin and py2exe

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

Sep 14 '05 #1
3 2556
"Mike Tammerman" <mt********@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
Sep 14 '05 #2
Yes, it throws exceptions if I build the exe of the subprogram.py.

So, is it possible to pipe some data to another py2exe'd application
without a console.

Mike

Sep 14 '05 #3
"Mike Tammerman" <mt********@gmail.com> writes:
Yes, it throws exceptions if I build the exe of the subprogram.py.

So, is it possible to pipe some data to another py2exe'd application
without a console.


I did this just some days ago. It required a little bit of
experimenting. This code executes the Windows XP ftp.exe console
program (but doesn't show a console), and reads its output. Here is the
relevant code snippet:

from subprocess import Popen, PIPE, STDOUT
# It seems subprocess doesn't open a console by default
# when run from a windows program
#
# Plus: For whatever reason, when running as py2exe'd GUI
# program, stdin=None doesn't work. We HAVE to specify PIPE for stdin,
# and we HAVE to use '... < NUL', and then stdin.close().
p = Popen("ftp.exe -s:upload.txt %s < NUL" % self._address,
cwd=os.path.join(util.get_main_dir(), "blah"),
shell=True,
stdin=PIPE,
stdout=PIPE,
stderr=STDOUT
)
p.stdin.close()
text = ""
while 1:
data = p.stdout.readline()
if not data:
break
<handle output data>
if p.wait():
<handle error>
return

The problem was that passing 'stdin=None' didn't work, for whatever
reason. I don't think it is a py2exe problem although the comment above
may suggest it.

Hope that helps,

Thomas
Sep 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
1
by: | last post by:
I want a binnary file to my aplicattion, but py2exe don't match the xmll.sax module. the py2exe shows this errors: warning: py2exe:...
2
by: Stefan Behrens | last post by:
Hi, does anybody know how I can get py2exe to work with wxPython's wxCalendarCtrl? Currently, I have just a "standard" setup.py, and py2exe gives me a syntax error. Do I need to include any...
0
by: Kathleen Kudzma | last post by:
I'm having a problem with py2exe for Python 2.3. I got fixed the Lookuperror no codec search functions registered: can't find encoding by following the instructions on the py2exe page (added...
8
by: Kathleen Kudzma | last post by:
Does anyone know how to resolve the following problem that I'm getting in Python 2.2 and 2.3? PROBLEM: When I try to create a classReader object I get an exception: "SAXReaderNotAvailable: No...
0
by: Steven Bell | last post by:
I am trying to build an executable from a python script. Using python 2.3, SOAPpy 0.10.3, Py2exe 0.4.2. Build command: python setup.py py2exe -w --includes xml.sax.drivers2.drv_py I get the...
6
by: Luc Saffre | last post by:
Hello, I had a strange problem when freezing (using either py2exe or McMillan installer) a script that imports reportlab (which imports PIL (which imports FixTk))). - Python 2.3.3c (also with...
0
by: Larry Bates | last post by:
Jimmy Retzlaff wrote: Everyone, Thanks for all your hard work on py2exe, it is greatly appreciated. -Larry Bates
0
by: Jimmy Retzlaff | last post by:
py2exe 0.6.9 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.