No such thing as a small change | |
PerlMonks |
Re^4: Perl Pipeline exception handling (inherit handle)by tye (Sage) |
on Jul 28, 2016 at 19:33 UTC ( [id://1168753]=note: print w/replies, xml ) | Need Help?? |
Inheritance of file handles in child processes is very similar between Unix and Windows. All of the same concepts are there in both places, but they have different names and are manipulated using different functions. Perl layers the Unix-style concepts over the top of the Windows equivalents. If you want to have a Perl child process on Windows inherit a file handle, it requires you to use the Windows concepts and then rewrap them in the Unix equivalents so Perl can use them (because Perl only does that for you automatically for STDIN, STDOUT, and STDERR). Win32API::File (bundled with Perl) provides all of the tools you need to do this. In Unix, to share a file handle with a child process that is not running the same script, that is, when you did fork(2) followed by exec (perhaps indirectly, such as via system), you have to:
In Windows, the steps are almost the same. Instead of a file descriptor, you deal with a native Windows "file handle" (a pointer, which is just a large integer), which you must not confuse with a Perl "file handle". The Windows steps are:
I've done this successfully without much trouble before. I thought I'd posted code for such here but my search did not turn such up. I might rewrite that later and post it. See also: Re^2: Passing a File Descriptor to a New Process on Windows (Win32API::File) - tye
In Section
Seekers of Perl Wisdom
|
|