stdin/stdout fileno() always returning -1 from windows service

C

chuck

I have found that sys.stdin.fileno() and sys.stdout.fileno() always
return -1 when executed from within a win32 service written using the
win32 extensions for Python.

Anyone have experience with this or know why?
 
J

Jeff Epler

I have found that sys.stdin.fileno() and sys.stdout.fileno() always
return -1 when executed from within a win32 service written using the
win32 extensions for Python.

Anyone have experience with this or know why?

because there *is* no standard I/O for a windows service.

You should be able to execute code like
import sys
sys.stdout = sys.stderr = open("some.log", "w")
if you have code that expects the standard output files to be available.
You could also open sys.stdin in a similar way.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFC267gJd01MZaTXX0RAj/RAJ4jGEDk6b+yTzvxtVUZPl04dilNVwCgijpF
8f8AN/H7Gt7yeB66i/0fFoc=
=7jBo
-----END PGP SIGNATURE-----
 
C

chuck

Interesting. The stdin and stdout objects in my service seems respond
to returing a string for the statements str(sys.stdin) and
str(sys.stdout). I guess they are just not attached to files?

Can you provide a reference (MSDN or otherwise) that indicates that
Windows Services don't have standard I/O?
 
J

Jeff Epler

It seems to simply be common wisdom. e.g.,
http://mail.python.org/pipermail/python-win32/2004-September/002332.html
http://mail.mems-exchange.org/pipermail/quixote-users/2004-March/002743.html
http://twistedmatrix.com/pipermail/twisted-python/2001-December/000644.html
etc

If you can find chapter and verse on MSDN, more power to you. This page
implies that the "standard handles" are only available when there is a
console for the application.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getstdhandle.asp

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFC280YJd01MZaTXX0RAoXFAJoCoLSFEoIqekw+vaZ5Q6YVx8Ob/wCgpodR
BWJyC4mpHLOON0cUYZa+qwA=
=wCK/
-----END PGP SIGNATURE-----
 
C

chuck

"common wisdom".... interesting.

The value of the closed attribute is "False" when tested from within
the service.

Still digging....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top