문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top