开发者

How to open / use a file descriptor

开发者 https://www.devze.com 2023-02-03 06:09 出处:网络
I have a particular problem, I have some program that I cannot modify but that provides some functionality I\'d like to use inside office. So I am writing a plugin for Office that takes my document, e

I have a particular problem, I have some program that I cannot modify but that provides some functionality I'd like to use inside office. So I am writing a plugin for Office that takes my document, executes the program on the background, puts the document on the stdin. The program writes to the stdout, and I take that back to my program to post process that.

This all works fine except that the program asks for a password which I don't want to put on stdin. The tool has a way to read the password from any other input stream but it needs the number of the file-descriptor it should read from.

So here is my question: how do I (within the .net environment) open a stream on a file descriptor with a number that I can give as parameter to this program? Ideally I want to write something like:

process.start("start-program --password-fd " + x);
stream = new StreamWriter(x);
stream.write("secrit开发者_JS百科pwd");

ect.. (but then magically corrected so it will work ;) )

I hope someone can help me.

Thanks


I'm not sure exactly what this app means by "file descriptor", but you may be able to pass the handle of an inheritable anonymous pipe. See AnonymousPipeServerStream. (This assumes you're on at least .NET 3.5.)

The basic outline would be something like this:

  • Instantiate an AnonymousPipeServerStream.
  • Pass the pipe handle (pipeServer.GetClientHandleAsString()) as a command-line parameter to your C executable.
  • Write to the AnonymousPipeServerStream.


File descriptors aren't part of Windows - they're part of the C runtime library. You would have to write a DLL in C or C++ to do your file I/O, then call it from your C# program. Get the file descriptor number from the C DLL to pass to your other code.


Maby this links will help you to start and to get the logic from:

How to use OpenFileById to open a file

Opening pipe connection to a file descriptor in C#

OpenFileById Function

0

精彩评论

暂无评论...
验证码 换一张
取 消