如何打开/使用文件描述符
我有一个特殊的问题,我有一些程序无法修改,但它提供了一些我想在办公室内使用的功能。所以我正在为 Office 编写一个插件,它获取我的文档,在后台执行程序,将文档放在标准输入上。该程序写入标准输出,然后我将其带回到我的程序中进行后期处理。
这一切都工作正常,除了程序要求输入密码,而我不想将其放在标准输入上。该工具可以从任何其他输入流读取密码,但它需要从中读取的文件描述符的编号。
所以这是我的问题:如何(在 .net 环境中)打开文件描述符上的流,并使用可以作为该程序参数提供的数字?理想情况下,我想写一些类似的东西:
process.start("start-program --password-fd " + x);
stream = new StreamWriter(x);
stream.write("secritpwd");
等等..(但随后神奇地纠正,所以它会起作用;))
我希望有人可以帮助我。
谢谢
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("secritpwd");
ect.. (but then magically corrected so it will work ;) )
I hope someone can help me.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这个应用程序的“文件描述符”到底是什么意思,但您也许可以传递可继承的匿名管道的句柄。请参阅AnonymousPipeServerStream。 (这假设您至少使用 .NET 3.5。)
基本概要如下:
pipeServer.GetClientHandleAsString()
) 作为命令行参数传递给 C 可执行文件。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:
pipeServer.GetClientHandleAsString()
) as a command-line parameter to your C executable.文件描述符不是 Windows 的一部分 - 它们是 C 运行时库的一部分。您必须用 C 或 C++ 编写 DLL 来执行文件 I/O,然后从 C# 程序中调用它。从 C DLL 获取文件描述符编号以传递给其他代码。
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.
也许这个链接将帮助您开始并从中获取逻辑:
如何使用 OpenFileById 打开文件
在 C# 中打开与文件描述符的管道连接
OpenFileById 函数
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