如何打开/使用文件描述符

发布于 2024-10-11 01:37:49 字数 481 浏览 3 评论 0原文

我有一个特殊的问题,我有一些程序无法修改,但它提供了一些我想在办公室内使用的功能。所以我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰魂雪魄 2024-10-18 01:37:50

我不确定这个应用程序的“文件描述符”到底是什么意思,但您也许可以传递可继承的匿名管道的句柄。请参阅AnonymousPipeServerStream。 (这假设您至少使用 .NET 3.5。)

基本概要如下:

  • 实例化 AnonymousPipeServerStream。
  • 将管道句柄 (pipeServer.GetClientHandleAsString()) 作为命令行参数传递给 C 可执行文件。
  • 写入 AnonymousPipeServerStream。

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.
时光沙漏 2024-10-18 01:37:50

文件描述符不是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文