Question about redirecting Cygwin process's I/O to the client side of an Win32 named pipe.

Chiheng Xu chiheng.xu@gmail.com
Thu Jul 19 18:14:00 GMT 2012


Hi, list

I'm working on a very small software component,  that can create a
Cygwin process, and redirect it's I/O to the client side of an Win32
named pipe.
The creating process now have a handle of the server side of the Win32
named pipe. The creating process can then write to/read from the
sub-process through the pipe handle.

This is pretty much like mintty, which spawn bash.exe by redirecting
bash.exe's I/O to the slave side of a pty.

But because the component is intended to be used by Win32 native apps,
like MFC apps, JNI, etc,  it is not plausible to use the pty
facilities provided by cygwin1.dll.
It is also not appropriate to dynamically load cygwin1.dll in the
creating process.


The method is below:
1. Win32 native A.exe  create a named pipe and own the handle to the
server side.
2. A.exe create a "detached" starter.exe process. This starter.exe get
the name of the pipe and the argvs of the B.exe(the to be created
Cygwin process) through its command line.
3. starter.exe get handle to client side of the pipe, and create
"detached" B.exe process redirecting its I/O to the client side of
pipe.

The idea comes from another open source project.
The use of the intermediate starter.exe is because, Cygwin process
B.exe will inherit all inheritable handles in parent process,
including the client side handle of the named pipe,  but we don't know
whether there exist other inheritable handles in parent process. So, a
"clean" process starter.exe that have no handles is created. The
starter.exe executable is even not linked with C run time, and have no
main(). It's entry is specified by compiler command line option.  So,
starter.exe is considered clean.

The problem here is that,  this method works for "simple" executable
like Windows's cmd.exe and Cygwin's gdb.exe, but does not work for
Cygwin's bash.exe or python.exe.
bash.exe process can be created, but I can't read data from the pipe.

So, what's wrong ?

What's the difference between bash.exe and gdb.exe or cmd.exe ?

What's the difference between Win32 named pipe and Cygwin pty ?

How can I make it work ?

Some code pieces is attached.



Thanks.

-- 
Chiheng Xu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A.cpp
Type: text/x-c++src
Size: 3834 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20120719/1e5de8dc/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: starter.cpp
Type: text/x-c++src
Size: 4597 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20120719/1e5de8dc/attachment-0001.bin>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list