如何使用 DELPHI 将文件写入 STDIN Stream?
我需要将文件写入 STDIN。该文件将由另一个 EXE 访问,该 EXE 将在微控制器中写入 STDIN 流。
您能否帮助我如何使用 Delphi 2010 将文件写入 STDIN?
非常感谢!
I need to write a FILE to STDIN. This FILE going to be accessed by another EXE that goig to write the STDIN stream in a microcontroller.
Could you give me a help how to write the file to STDIN using Delphi 2010?
Thanks very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的意思是标准输出。
Allen Bauer 的答案是你要买什么?
I think you mean STDOUT.
Is the Allen Bauer's answer is what are you looking for?
看起来您正在尝试写入某种输出,其他 EXE 会将其视为其 STDIN 流。在这种情况下,Serg 提到的 Allen Bauer 的答案很接近,但对您来说还不够。
MSDN 上有一些 示例代码这解释了如何做到这一点,但它都是用 C 编写的,很难阅读。重要的部分是这样的:
调用CreatePipe,它在Windows.pas中声明。前两个参数是 THandle 变量的 var 参数,CreatePipe 将使用管道的读取句柄和写入句柄填充这些变量。然后你需要设置一个TStartupInfo记录。将管道的读取句柄分配给 TStartupInfo 的
hStdInput
字段。您将 TStartupInfo 传递给 CreateProcess 以生成第二个 EXE,然后您可以像 Allen 的示例一样创建一个 THandleStream,并将管道的写入句柄传递给它。这样,您写入流中的任何内容都会通过管道传输到读取端,以便由另一个 EXE 读取。
希望有帮助...
It looks like you're trying to write to some sort of output that the other EXE will see as its STDIN stream. In that case, Allen Bauer's answer mentioned by Serg is close, but it's not going to be enough for you.
There's some sample code on MSDN that explains how to do this, but it's all in C and hard to read. The important part is this:
Call CreatePipe, which is declared in Windows.pas. The first two parameters are var parameters to THandle variables that CreatePipe will fill with the read handle and the write handle of the pipe. Then you need to set up a TStartupInfo record. Assign the read handle to your pipe to the
hStdInput
field of the TStartupInfo.You pass the TStartupInfo to CreateProcess to spawn the second EXE, and then you can create a THandleStream like in Allen's example, passing it the write handle of the pipe. That way, anything you write into the stream gets piped to the read end to be read by the other EXE.
Hope that helps...