如何调用外部程序并从另一个程序获取其输出

发布于 2024-10-14 07:45:17 字数 462 浏览 7 评论 0 原文

如何在 C++ 中执行此操作:

假设程序 A 是一个带有一些输入(例如文件路径和数字)的命令行工具,根据它的输入,它可能会在运行时获取一些其他参数。 (if(condithin) cin<) 我想从另一个程序 B 调用 A 并希望查看完整的输出A 在运行期间。必须输入 A 的输入(如有必要)。 B 是一个用 Qt 编写的 GUI 工具,A 必须显示在纯文本区域中,并且它的输入必须显示在同一位置(如控制台客户端)。

我只是不知道从哪里开始。阅读有关 IPC 的内容并没有帮助。我知道这是可能的,因为我在 Eric IDE 中看到了 Dolphin 的控制台窗口和 python 解释器......

Howto do this in c++:

Suppose that program A is a command line tool with some inputs (for example file paths and a number), according to it's inputs, it may get some other parameters during runtime. (if(condithin) cin<<something) I'd like to call A from another program B and want to see complete output of A during it's running. A's inputs must be entered (if necessary). B is a gui tool written with Qt and A must be shown in a plain text area and it's inputs must be shown in same place (like a console client).

I just don't know where to start. Reading something about IPC didn't help. I know it's possible because I see Dolphin's console window and python interpreter in Eric IDE...

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

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

发布评论

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

评论(2

深居我梦 2024-10-21 07:45:17

使用 QProcess::execute 方法开始运行 A。你可以形成从 B 传递到 A 的参数列表。使用 QProcess::readAllStandardOutput () 读取进程的输出并显示在 B 中。

use QProcess::execute method to start running A. you can form the argument list from B to pass to A. Use QProcess::readAllStandardOutput () to read the output of the process and display in B.

-小熊_ 2024-10-21 07:45:17

由于您使用 Qt,因此使用 QProcess 可能是最好的方法。

Since you use Qt, using QProcess is probably the best way to do it.

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