-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to connect to extra stdIO streams/pipes #26559
Comments
Stream s = new FileStream(new SafeFileHandle((IntPtr)3, ownsHandle: false), FileAccess.ReadWrite); ? |
I'm getting an |
Are you sure your process has file descriptor 3 as you expect it? When your process is running, what do you see as output from doing:
where It sounds like file descriptor 3 is something else. (I'm assuming you're running on Linux... the above won't work if you're on mac.) |
Oh, maybe I misunderstood the original question. Are you saying that some other process has file descriptors 3 and 4 open and you want to somehow connect to those? You would need to know what interprocess mechanism that other process is using on those file descriptors. In your process, that other process' fds 3 and 4 have no meaning at all; they're just the numbers that process is using. You would need to use whatever mechanism it's expecting to connect. |
I'm on a mac. There from the code it's just about declaring 2 pipes and that's all https://github.com/GoogleChrome/puppeteer/blob/master/lib/Launcher.js#L115 I'm trying to mimic that. |
Maybe I am the one who needs to create those FDs. |
As far as I can tell, that's all using NodeJS-specific mechanisms / implementation / patterns / helpers, with node being used in both the parent and child process, and thus it using its own agreed upon handshake for how to set up these pipes. You would need to fully understand the implementation in order to simulate it. |
@stephentoub well, Chromium is not a NodeJS app. |
Let me rephrase my questions then:
|
That's what I'm trying to understand. I don't play with this kind of stuff every day, and I need to set the boundaries between "NodeJS idioms" and standard behaviors. That's why I tried to make this issue as generic as possible, because these guys are using standard File Descriptors, which I think it's the main question: "How can I create/read/write some other FDs besides stdIn stdOut and stdError". I first need to be able to connect these two FD before start digging into the protocol itself. In NodeJS that looks pretty transparent: "Those pipes are streams like StandardInput and StandardOutput". |
I think this is the part that's confusing the issue, or at least confusing me :) There are only three "standard" file descriptors: stdin (0), stdout (1), stderr (2). And all that means is that apps should expect those file descriptor numbers to map to those concepts, so that when a parent process launches a child process and configures the child process, it can set up 0/1/2 in the child process appropriately and the child process can similarly expect that 0/1/2 mean what it thinks it means.
Ok, so that code in the child process is expecting that the parent process has configured its file descriptors 3 and 4.
When a process starts a child process, it does so by So, for example, if a parent process wants to set up the child process' stdin, stdout, and stderr to be pipes that the parent process can read/write, for each it would call Thus, what I believe you're asking for is some way to augment the Process class, Process.Start, and the above SystemNative_ForkAndExecProcess logic to say "please create an additional N pipes and dup the child ends onto these specific additional fd numbers I provide, then return to me Streams from the Process returned from Process.Start that wraps the parent ends of those pipes". Have I understood correctly? If so, that's a tall ask. In particular, I don't know what that would mean in a Windows world where things operate very differently, so such functionality would likely end up being Unix-specific on a type that's meant to work as equivalently as possible everywhere. It also seems to be super-specific to this one scenario, though admittedly if NodeJS added support for this, maybe they had additional known scenarios in mind. But, never say never. If you have a specific API in mind for accomplishing this, please share what you would want it to look like. Given all that, to answer your three original questions:
Yes. This isn't related to how Console opens the current process' stdin/stdout/stderr. It's about configuring a spawned child process' file descriptors after
No, I don't know of any way to do what you want reliably today.
Those classes aren't what you want and wouldn't help you here. As noted above, the code that spawns processes would need to be modified to support creating and dup'ing additional file descriptors after the |
Exactly. That would be the feature I need. But it's also important for me to know if this is something I can accomplish now or not. Thanks for taking the time to go through this issue. |
@kblok I'm closing this as abandoned, please re-open if you still have interest in this issue. |
Context
I'm trying to connect to Chromium using the flag
--remote-debugging-pipe
. When that flag is used, Chromium will listen and write to pipes using the stdIO/File Descriptors 3 and 4 (https://github.com/chromium/chromium/blob/a5f23780e29ab3d8f58269bd69bdc297beeed2f9/content/browser/devtools/devtools_pipe_handler.cc#L32).Problem
I found no way to connect to those pipes using the Process class. So I went to the Console Class to see how the Standard Output is being opened.
The problem is that, from that point, going deeper, all the classes and methods are internal.
I can't use Interop.Sys.Dup to open the FD myself. I can't use SafeFileHandleHelper to open streams like Console does.
So my questions would be:
The text was updated successfully, but these errors were encountered: