do anonymous pipes normally work on NT?
radbit at my-deja.com
radbit at my-deja.com
Wed Jun 16 15:08:11 EDT 1999
In article <4D0A23B3F74DD111ACCD00805F31D8100DB90DDC at RED-MSG-50>,
Bill Tutt <billtut at microsoft.com> wrote:
> Well, I finally noticed this thread, and I'll chime in with what I
found out
> so far:
> (No, I haven't figured it all out yet, its time for sleep.)
>
> Symptoms:
> python -u cat.py < cat.py is allowed to read from stdin.
> python cat.py < cat.py isn't allowed to read from stdin.
> python -u cat.py > blah is allowed to write to stdout
> python cat.py > blah isn't allowed to wrtie to stdout.
> python runproc.py (with -u) cat.py isn't allowed to write to stdout
> python runproc.py cat.py isn't allowed to write to stdout.
>
> -u does two things:
> 1) turns stdin/stdout into binary streams
> 2) turns off stdio buffering
Hi
maybe I'm missing something about what you are looking for: here are 2
test scripts that work as anonymous pipes:
file runproc.py
---------------
'''runproc.py
start a process with three inherited pipes.
Try to write to and read from those.
'''
import win32api
import win32pipe
import win32file
import win32process
import win32security
import win32event
import os
#Constants for stdandard handles
STD_ERR_HANDLE=-12
STD_OUTPUT_HANDLE=-11
STD_INPUT_HANDLE=-10
class Process:
def run(self, cmdline):
# security attributes for pipes
sAttrs = win32security.SECURITY_ATTRIBUTES()
sAttrs.bInheritHandle = 1
# create pipes
hStdin_r,self.hStdin_w=win32pipe.CreatePipe(sAttrs, 0)
self.hStdout_r,hStdout_w=win32pipe.CreatePipe(sAttrs,0)
self.hStderr_r,hStderr_w=win32pipe.CreatePipe(sAttrs, 0)
#associate Standard output to previously open handle
win32api.SetStdHandle(STD_OUTPUT_HANDLE,hStdout_w)
# set the info structure for the new process.
StartupInfo = win32process.STARTUPINFO()
# start the process.
hProcess, hThread, dwPid, dwTid=win32process.CreateProcess(
None, #program
cmdline,# command line
sAttrs, # process security attributes
sAttrs, # thread attributes
1, # inherit handles,
win32process.NORMAL_PRIORITY_CLASS,
None, # no new environment
None, # current directory (stay where we are)
StartupInfo)
# normally, we would save the pid etc. here...
res, str = win32file.ReadFile(self.hStdout_r,100)
if res == 0: print 'read:', str
else: 'read nothing.'
if __name__ == '__main__':
p = Process()
p.run('..\\python.exe testpipe.py')
-----------------
end of runproc.py
file testpipe.py
----------------
import win32api
import win32file
STD_ERR_HANDLE=-12
STD_OUTPUT_HANDLE=-11
STD_INPUT_HANDLE=-10
std_in=win32api.GetStdHandle(STD_INPUT_HANDLE)
std_err=win32api.GetStdHandle(STD_ERR_HANDLE)
std_out=win32api.GetStdHandle(STD_OUTPUT_HANDLE)
win32file.WriteFile(std_out, 'this method works....')
end of testpipe.py
------------------
Cheers
Florent Heyworth
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
More information about the Python-list
mailing list