Piping using the Netscape Portable Runtime

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.

 

any updates?

Hi, I implemented my program using nsIPrcoess, the issue I was facing was paths, just like you suggested.

I still have the ugly dos window pop up and then disappear after the resizing of the image is done, humph told me you are working on capturing the stdout of a nsIPrvoess. Have you got this done?

Command shell Pop-up?

I'm interested in hearing more about the command shell appearing, because this was thought to be a solved problem:

xpcom/threads/nsProcessCommon.cpp#254

Windows processes are started with the CREATE_NO_WINDOW flag to prevent that happening. Can you provide more details about your Firefox version and OS?

As for piping, I'm not expecting to have a patch for that until January. Something that supports asynchronous I/O and will ship won't come until after that. From what I understand, Gecko has image resizing code baked in and you would probably get a finer grain of control by using it.

RSS

Syndicate content