Since my approach to fixing nsIProcess has been to take advantage of code that alraedy exists in the Netscape Portable Runtime, I've been hunting in there for something that might be useful for inter-process communication. What I need is something for capturing the stdout of a process or for sending stuff to its stdin. Well, it looks like the NSPR has an API for i/o redirection.
nsprpub/pr/include/prproces.h#59
NSPR_API(void) PR_ProcessAttrSetStdioRedirect(
PRProcessAttr *attr,
PRSpecialFD stdioFd,
PRFileDesc *redirectFd
);
nsprpub/pr/include/prio.h#1891
NSPR_API(PRStatus) PR_CreatePipe(
PRFileDesc **readPipe,
PRFileDesc **writePipe
);
The PRProcessAttr* appears to be the key here. If you look at the implementation for PR_ProcessAttrSetStdioRedirect you can see that that PRPRocessAttr* contains the information about piping:
nsprpub/pr/src/misc/prinit.c#520
PR_ProcessAttrSetStdioRedirect(
PRProcessAttr *attr,
PRSpecialFD stdioFd,
PRFileDesc *redirectFd)
{
switch (stdioFd) {
case PR_StandardInput:
attr->stdinFd = redirectFd;
break;
case PR_StandardOutput:
attr->stdoutFd = redirectFd;
break;
case PR_StandardError:
attr->stderrFd = redirectFd;
break;
default:
PR_ASSERT(0);
}
}
Although PRProcessAttr* is the fourth term in the PR_CreateProcess signiture, it isn't used in the nsIProcess invocation:
xpcom/threads/nsProcessCommon.cpp#371
PR_CreateProcess(mTargetPath.get(), my_argv, NULL, NULL);
I think I can use the NSPR API to create pipes and then pass them to PR_CreateProcess as a PRProcessAttr*. In this way I can expose i/o piping for processes in nsIProcess.
There isn't any documentation for this that I can find, but someone has been good enough to write some unit tests for this stuff that gives me an idea of how it works:
nsprpub/pr/tests/pipeping.c#119
I think this stuff may have been created with file i/o in mind, but I'm not sure that matters.