in reply to Problems forking and redirecting STDOUT with Win32
Process can inherit Win32 handles. Notice that i am specifying Win32 handles, not Perl file handles; this is very important. (...) If the new process you create is a Perl script, however, don't expect to be able to access those opened sockets and files you inherited. This is because a Perl file handle differs from a Win32 handle. You see, Perl creates a file handle by asking the C language's runtime library to open the file. The C library, in turn, asks the operating system to open it. The Win32 API will return a handle (...) , and the C library will store the handle into some data structure it creates. A pointer to this structure will be returned to Perl, which puts this pointer into yet another structure. Perl will then associate a Perl file handle (...) with this structure. Because a new process does not have access to memory in other process, any inherited memory pointer won't point to the original memory structure.
This means (as he concludes soon after) that only the Win32 file handle is inherited and not the Perl file handle.
He suggests to use Win32::AdminMisc::GetStdHandle but the book is a bit outdated and my option is to use Win32::Job which allows to pass handles around.
HTH,
secret .
|
|---|