如何将 stdin 从我的应用程序重定向到另一个知道其 PID 的应用程序(C,在 Windows 中)

发布于 2024-08-19 08:13:51 字数 289 浏览 4 评论 0原文

我有一个脚本 vbs,它将一些数据重定向到 myApp 的标准输入(在 Windows 中用 C 编写)。 如果 myApp 在 myApp 找到第一个 myApp 会话的 PID 之前已经启动,并将通过 stdin 接收到的输入重定向到处理该 stdin 的 myApp 第一个会话的 stdin。 因此,当 myApp 接收到一个标准输入并且没有其他 myApp 实例正在运行时,它会处理该标准输入并对其进行处理。 所以问题是:如何将 stdin 从一个应用程序重定向到另一个知道第二个 spp 的 PID 的应用程序? 语言=C 平台 = MSwindows

I have a script vbs wich redirect some data to the stdin of myApp (written in C in Windows).
If myApp was already launched before myApp finds the PID of the first myApp session and redirects the input received via stdin to the stdin of the first session of myApp which handles the stdin.
So when myApp receives a stdin and no other instances of myApp are running it handles the stdin and does stuff with it.
So the question is : how to redirect stdin from an app to another knowing the PID of this secnd spp?
language = C
platform = MSwindows

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

妄想挽回 2024-08-26 08:13:52

这对你有用吗? http://msdn.microsoft.com/en- us/library/ms682499%28VS.85%29.aspx

本文使用匿名管道创建一个具有重定向 IO 的子进程,您可以使用命名管道。使用此函数:http://msdn.microsoft。 com/en-us/library/aa365144%28VS.85%29.aspx 您可以测试命名管道是否已存在 - 如果不存在,您可以创建一个并等待其输入。

我不确定是否有多个文件写入同一个命名管道 - 我假设所有数据都像一个文件一样通过,因此我将使用一个命名管道作为协商者,它为每个客户端实例化一个新的命名管道并添加其管道到要等待的管道列表。通过新管道发送一条消息将其关闭。

我不认为(如果我错了,请纠正我)重定向另一个进程的句柄并不那么容易。

Is this any use to you? http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx

This article creates a child process with re-directed IO using anonymous pipes, you could use named pipes. Using this function: http://msdn.microsoft.com/en-us/library/aa365144%28VS.85%29.aspx you can test if a named pipe already exists - if it doesn't, you can create one and wait on its input.

I'm not sure r.e. multiple files writing to the same named pipe - I assume all the data comes through as if one file, so I'd use one named pipe as a negotiator which instantiates a new named pipe per client and adds its pipe to the list of pipes to wait on. Close it with a message through the new pipe.

I don't think (someone correct me if I'm wrong please) it is that easy to redirect handles of another process.

泛滥成性 2024-08-26 08:13:52

好的,有机会编写程序的源代码,我将转向命名管道的想法。
App1的主进程将检查App的另一个实例(即App0)是否已经在运行。如果是这样,App1 接收到的 stdin 将被重定向到命名管道 X。
App0 使用命名管道 X 持续接收输入。
因此 App0 和 App 的所有其他实例(App2、e、4...)将通过命名管道进行通信。
非常感谢九指,你太有帮助了!

Ok having the chance of writing the source of the program I'll move toward the idea of named pipes.
The main process of App1 will check if another instance of App (i.e. App0) is already running. If so the stdin received by App1 will be redirected to a named pipe X.
App0 keeps receiving inputs using the named pipe X.
So App0 and all others instances of App (App2,e,4...) will communicate via the named pipe.
Thankyou very much NineFingers, u were so helpful!

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