Joe Schell, I have two things to say. First, thanks for the thoughtful
reply. Second, you have a seriously cool name.
OK, to the technology.
>> when you use the redirection symbol '>' without any number in
>> front, *both* STDERR and STDOUT go to the same place together.
>I don't believe that is correct. As far as I know on unix, NT and
>alternative command shells for Win 9x, when you use ">" it redirects
>stdout, stderr is not redirected.
You are correct, Joe. stderr is not redirected. > just
redirects stdout.
>The standard shell in Win 9x does not have a way of redirecting
>stderr, however it does exist. When writing a C program there are
>two different file descriptors '1' and '2', which one can do
>interesting things with if one is so inclined. I believe
>'0' is stdin.
This leads to what I've been thinking about this weekend (while
resisting flaming a troll)...
The basic problem is, Unix redirection syntax isn't fully supported by
Win32 command lines. So while the MS world since early DOS has
actually had five independent redirectable streams (stdin, stdout,
stderr, stdaux, stdprn), there is no actual command-line means of
specifying redirection for any but stdin and stdout.
I'd like to explore solving this, for Perl at least. There are two
ways to do it I can think of:
First, modify how Perl actually calls the shell. Add parsing
of the command string, searching for Unix-specific redirection. Then
open an appropriate file (temporary or persistent) and place the
file handle into the structure fed to the CreateProcess()
call; all DOS and Windows variants have the ability to start a
child process which inherits the needed file handles (stdin, stdout,
stderr). Heck, I wrote TSR's back in the 80s that could handle a
console -- this would be MUCH easier.
The second possibility is to only very lightly modify Perl, calling a
new C function. That is, do the redirection parsing on the C side
rather than in Perl.
Either way is technically possible and approachable, but I strongly
favor the first approach. Here is a quick summary of the approach:
* Check command lines destined for the command shell for the 2>
redirection syntax. Might as well parse for other allowed
numerical file descriptors too -- handling should be
equivalent.
* In the parent process, save the current stderr with a call to
GetStdHandle(STD_ERROR_HANDLE);
* Create a pipe (CreatePipe(&hRead,&hWrite,&attr,0);), and assign
its read handle to be stderr for the parent process with
SetStdHandle(STD_ERROR_HANDLE,hRead);
* Call DuplicateHandle() on the (unneeded for
stderr) write handle for the pipe. Sample call:
DuplicateHandle(GetCurrentProcess(),&hWrite,GetCurrentProcess(),
&hDuplicateHandle,0,FALSE,DUPLICATE_SAME_ACCESS);
and then close the original - CloseHandle(hWrite);
* Then create the child process. stderr will be redirected. As soon
as the process is created, you can restore the original state of
the stderr file handle for the parent process with SetStdHandle().
Further handling for stderr (reading what's written to the pipe by
the child process) would be exactly the same as for stdout.
A clear explication of this method can be found on MSDN, in a topic
called "Creating A Child Process With Redirected Input and Output".
All the functions specified were supported back all the way to
Win95, and I can tell you that equivalent mechanisms were available
in very early DOS versions.
I'd love any feedback from Joe, or anyone actually interested in
getting Perl as functional as possible on Win32, for such I perceive
to be the charter of this list.
If anyone at ActiveState is monitoring this list, I'd love to help
implement this feature. I'm not part of the active Perl
developer community; I'd be glad to pitch in, but I've not got the
time to figure out where to offer help. As always, human interaction
is more difficult for old engineers than is writing code. Hehe.
Please feel free to contact me directly, if I can help.
Sorry for going on and on, but I think if we want to, we can
actually solve this particular issue once and for all. This would
get rid of one more nagging incompatibility.
Now I've got to go hook up my stereo. It helps me to think of
"left" and "right" as two redirectable streams...
--- John
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users